List - A SIMPLE LIST CLASS WITH ITERATORS#ifndef...

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

View Full Document Right Arrow Icon
A SIMPLE LIST CLASS WITH ITERATORS ****/ #ifndef LIST_H #define LIST_H #include <cassert> template <class T> class List; template <class T> class List { public: class Iterator; friend class Iterator; protected: struct Node { T data; Node *next; Node() {next = 0;} Node(const T& a, Node *p = 0) {data = a; next = p;} }; Node *head, *tail; public: List() {head = tail = 0;} List(const List &aList); const List& operator=(const List &aList); ~List() { SetToEmpty(); } void AddFirst(const T& a); void RemoveFirst(); void AddLast(const T& a); bool IsEmpty() const; const T& ShowFirst() const; void SetToEmpty(); void AddAfter(Iterator i, const T& item); void RemoveAfter(Iterator i); class Iterator { friend List; private: Node *nodePointer; // construct an iterator and set it to a given node Iterator(const Node *setPtr) { nodePointer = const_cast<Node *> ( setPtr ); } public: //default constructor Iterator() : nodePointer( 0 ) {} // return reference of the item pointed by Iterator
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

List - A SIMPLE LIST CLASS WITH ITERATORS#ifndef...

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

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