List, Stack and Queue

List, Stack and Queue - CSC2100a Tutorial Lists, Stacks and...

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

View Full Document Right Arrow Icon
CSC2100a Tutorial Lists, Stacks and Queues Spring 2006/2007
Background image of page 1

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

View Full DocumentRight Arrow Icon
Linked list - overview •L in ked L i
Background image of page 2
Linked list - implementation • template<class Object> class List; //the list itself • template<class Object> class ListItr; //represents the position • template<class Object> class ListNode //represents the node { :element( theElement ), next(n) {} Object element; ListNode *next; friend class List<Object>; friend class ListItr<Object>; };
Background image of page 3

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

View Full DocumentRight Arrow Icon
Linked list - implementation • template<class Object> class ListItr //represents the node { public: ListItr() : current (NULL) {} bool isPastEnd() const {… } void advance() {…} const Object & retrieve () const {…} private: ListNode<Object> *current;//Current position ListItr(ListNode<Object> *theNode) : current ( theNode ) {} friend class List<Object>; //Grant access to constructor }; bool isPastEnd() const { return current == NULL; } void advance() { if (!isPastEnd()) current = current->next; } { if( isPastEnd()) throw BadIterator(); rerurn current->element; }
Background image of page 4
Linked list - implementation template<class Object> class List
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 21

List, Stack and Queue - CSC2100a Tutorial Lists, Stacks and...

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

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