1-26

# 1-26 - Problem Solving with Computers-II CS 24 1...

This preview shows pages 1–11. Sign up to view the full content.

Problem Solving with Computers-II CS 24 January 26, 2010 1

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

View Full Document
Announcements Lecture notes available online (www.cs.ucsb.edu/~cs24) Username: ucsb-cs24 Password: w10-cs24 Wednesday’s Lab section Repeat last week’s lab exercise with pointer-based implementation Missing textbook(s) GauchoSpace will be used for Posting announcements Discussion Grades 6 students have not signed on yet Programming project Midterm on Thursday 2
Recap Abstract Data Types Specification (What?) Implementation (How?) Unsorted lists Array-based implementation Pointer-based implementation Questions Reference vs. value type Comparing enumerated types Exceptions 3

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

View Full Document
Lecture Plan Linked list implementation of unsorted list Time complexity of algorithms Big Oh 4
ADT Unsorted List Transformers MakeEmpty InsertItem DeleteItem Observers IsFull GetLength RetrieveItem Iterators ResetList GetNextItem change state observe state process all 5

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

View Full Document
// SPECIFICATION FILE ( unsortedType.h ) #include “ItemType.h” struct NodeType; class UnsortedType // declares a class data type { public : // 8 public member functions UnsortedType(); void MakeEmpty( ); bool IsFull( ) const; int GetLength( ) const; // returns length of list void RetrieveItem( ItemType& item, bool& found ); void InsertItem( ItemType item ); void DeleteItem( ItemType item ); void ResetList( ); item ); 6 Specification
Linked List Implementation (private part) private: NodeType* listData; int length; NodeType* currentPos; struct NodeType { ItemType Info; NodeType *next; } List with two items 7

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

View Full Document
Linked List Implementation How do you know that a linked list is empty? listData is NULL What should the constructor do? Set length to 0 Set listData to NULL What about currentPos? We let ResetList take care of initializing currentPos 8
Linked List Implementation What about the observers IsFull and GetLength ? GetLength just returns length Can a linked list ever be full? Yes, if you run out of memory Ask for a new node within a try/catch 9

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

View Full Document
bool Unsortedtype::IsFull() const { NodeType* location; try { location = new NodeType; delete location; return false; } catch (std::bad_alloc exception) { return true; } } What about MakeEmpty ? 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 37

1-26 - Problem Solving with Computers-II CS 24 1...

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

View Full Document
Ask a homework question - tutors are online