Lecture05

Lecture05 - 4/12/10 CMPSC24:Lecture5 AbstractDataType:Lists...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
4/12/10 1 CMPSC 24: Lecture 5 Abstract Data Type: Lists Divyakant Agrawal Department of Computer Science UC Santa Barbara 4/12/10 1 Announcements Programming Assignment 1: Due Friday April 16, 2010 CMPSC 24 HelpDesk: Sunday through Thursday: 7PM‐9PM Send mail to [email protected] One of the TAs will be on‐call to answer queries Intended primarily for debugging help HelpDesk versus Office Hours: discuss 2 4/12/10 LINKED LISTS C++ CLASS: PUTTING IT TOGETHER 4/12/10 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/12/10 2 Example linkedlist.h #include <iostream> // compiler direc\ves using namespace std; // compile direc\ves Class linkedlist{ private: struct node{ int data; node *link; } *list; public: linkedlist(); // Constructor void append( int num ); // append a node with “num” void delete( int num ); // delete the node containing “num” bool fnd( int num ); // TRUE iF “num” exists in the list ~linkledist(); // Destructor (to ensure no memory leak) }; 4/12/10 4 Skeleton oF linkedlist.cpp linkedlist::linkedlist() { p=NULL; } void linkedlist::append(int num) { // the code we developed goes in here . . } void linkedlist::delete(int num) { // the code we developed goes in here } 4/12/10 5 Skeleton oF linkedlist.cpp bool linkedlist::fnd(int num) { // the code we developed goes in here . . } Linkedlist::~linkedlist() { // ask the students what should happen here? . . } 4/12/10 6
Background image of page 2
4/12/10 3 Usage of linkedlist Class int main() { linkedlist myList; myList.append(35); myList.append(45); myList.append(37); if myList.Fnd(36) cout<<“36 on the list????”<endl; else cout<<“36 not on the list!!!”<<endl; // you should get the idea… // would it be nice to have myList.display() ??? LeM as an exercise!!! } 4/12/10 7 Recap Abstract Data Types SpeciFca\on (What?) Implementa\on (How?) 8 4/12/10 LIST ADT 4/12/10 9
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/12/10 4 10 Sorted and Unsorted List ADTs UNSORTED LIST Elements are placed into the list in no parBcular order. SORTED LIST List elements are in a sorted order‐‐‐either numerically or alphabeBcally by the elements themselves, or by a component of the element (called a KEY member). Name some possible keys 4/12/10 ADT Unsorted List Transformers MakeEmpty InsertItem DeleteItem Observers IsFull GetLength RetrieveItem Iterators ResetList GetNextItem change state observe state process all 11 4/12/10 ADT Unsorted List Common vocabulary
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

Page1 / 11

Lecture05 - 4/12/10 CMPSC24:Lecture5 AbstractDataType:Lists...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online