1-26

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

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

View Full Document Right Arrow Icon
Problem Solving with Computers-II CS 24 January 26, 2010 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

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

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

View Full DocumentRight Arrow Icon
// 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
Background image of page 6
Linked List Implementation (private part) private: NodeType* listData; int length; NodeType* currentPos; struct NodeType { ItemType Info; NodeType *next; } List with two items 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 37

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

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

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