#ifndef Node362 #define Node362 // A simple templated node class // Beth Katz - February 2011 // Constructor // Node(const T & newData = T( ), Node * newLink = NULL) // if initial values are not provided // initializes node data to default T object and NULL // No Destructor // Accessors // T getData( ) const // returns the data // Node * getLink( ) // returns the link (this returned value is non-constant) // const Node * getLink( ) const // returns the link (this returned value is constant) // Mutators // void setData(const T & newData) // sets the data to newData // void setLink(Node * newLink) // sets the link to newLink // Type T may be any type with a default constructor, // a copy constructor, and an assignment operator #include template class Node { public: explicit Node(const T & newData = T( ), Node * newLink = NULL) : data(newData), link(newLink) { } T getData( ) const { return data; } Node * getLink( ) { return link; } const Node * getLink( ) const { return link; } void setData(const T & newData) { data = newData; } void setLink(Node * newLink) { link = newLink; } private: T data; Node * link; }; #endif /* Node362 */