List(3) - #ifndef _LIST #define _LIST #include ...

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

View Full Document Right Arrow Icon
#ifndef __LIST #define __LIST #include <stdexcept> #include <string> /** * Doubly-linked list class */ template <typename ItemType> class List { protected: /** * Node struct * The node stores data and links to the previous and next nodes in the list. */ struct Node { ItemType _data; //The data stored in this node Node *_next; //Pointer to the next node in the list. Node *_prev; //Pointer to the previous node in the list. /** * Construct a new instance of a Node. * * param data: the data to be stored in the node. * param next: pointer to the next node in the list. * param prev: pointer to the previous node in the list. */ _data(data), _next(next), _prev(prev) { } }; public: /** * iterator class */ class iterator { private: Node *_current; //the current node the iterator is pointing at. public: /** * Construct an iterator not pointing to anything. */ iterator() : _current(NULL) { } /** * Copy an existing iterator. * * param other: the iterator to duplciate. */ /** * Construct an iterator pointing to a specified node. *
Background image of page 1

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

View Full DocumentRight Arrow Icon
* Note that the Node class is a private inner class, so this * constructor can only be used from withing the List class. * * param loc: the location in the list to have the iterator point to. */ iterator(Node* loc) : _current(loc) { } /** * Access the data stored at the location that the iterator points to. (read-write) * * Returns a refence to the data stored on the list. */ return _current->_data; } /** * Access the data stored at the location that the iterator points to. (read-only) * * Returns a refence to the data stored on the list. */ return _current->_data; } /** * Access a pointer to the data stored at the location that the iterator points to. (read-write) * * Returns a pointer to the data stored on the list. */ ItemType* operator->() {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/03/2011 for the course CSCI 180 taught by Professor Goldwasser,m during the Fall '08 term at Saint Louis.

Page1 / 8

List(3) - #ifndef _LIST #define _LIST #include ...

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

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