Please send questions to st10@humboldt.edu .
/************************************************************/
/* ADAPTED FROM:                                            */
/* http://www.cs.colorado.edu/~main/chapter4/node1.h        */
/*                                                          */
/* Main and Savitch, "Data Structures and Other Objects     */
/*    using C++", 2nd edition, Addison-Wesley, Ch.5,        */
/*    p. 210 (mostly)                                       */
/************************************************************/

//---------------------------------------------------------------------
// File: node.h
// Name: Michael Main, Walter Savitch
//       (adapted by Sharon M. Tuttle)
// last modified: 3-10-05
//
// Class name: node 
//
// Description: serves as the unit from which a singly-linked list
//    can be built.
//
// DYNAMIC MEMORY USAGE by the node class:
//    If there is insufficient dynamic memory, then the
//       following throw bad_alloc:
//          the constructors, 
//
// NOTE: 
//    Some of the methods have return value that is
//       a pointer to a node. Each of these comes in TWO
//       versions: a non-const version (where the return value is
//       node*) and a const version (where the return value is
//       const node*).
//---------------------------------------------------------------------

#ifndef NODE_H
#define NODE_H

#include <cstdlib>      // provides size_t and NULL
using namespace std;

class node
{
    public:
        /****************************************************/
        /* TYPEDEFS and MEMBER CONSTANTS                    */
        /****************************************************/

        // node::value_type is the data type of the data_field
        //    of the node. It may be of any of the C++ built-in
        //    types (int, char, etc.), or a class with a 
        //    default constructor, a copy constructor, an
        //    assignment operator, and a test for equality
        //    (x == y).
        //
        // (CHANGE to desired type...)
        //
        typedef double value_type;

        /*****************************************************/
        /* CONSTRUCTORS and DESTRUCTOR                       */
        /*****************************************************/

        // postcondition: creates a node with data_field obtained from
        //    the default constructor of the value_type, and
        //    next_field set to NULL.
        //
        node( );

        // postcondition: creates a node with data_field set to
        //    init_data, and next_field set to NULL.
        //
        node(const value_type& init_data);

        // postcondition: create a node with data_field obtained from
        //    the default constructor of the value_type, and
        //    next_field set to init_next.
        //
        node(node* init_next);

        // postcondition: create a node with data_field set to
        //    init_data, and next_field set to init_next.
        //
        node(const value_type& init_data, node* init_next);

        /*************************************************************/
        /* ACCESSORS and other constant member functions (observers) */
        /*************************************************************/

        // postcondition: returns the data from this node
        //
        value_type get_data( ) const;
   
        // postcondition: returns the next pointer from this node.
        //    (See note above --- need both a const and non-const
        //    version of this, because it returns a pointer.
        //    See also pp. 219-221 of Savitch and Main, 3rd edition.)
        //
        const node* get_next( ) const;
        node* get_next( );

        /*****************************************************/
        /* MODIFIERS and other modifying member functions    */
        /*****************************************************/

        // postcondition: the node now contains the specified
        //    new_data.
        //
        void set_data(const value_type& new_data);

        // postcondition: the node now contains the specified
        //    new_next pointer.
        //
        void set_next(node* new_next);

    private:

        /*****************************************************/
        /* DATA FIELDS                                       */
        /*****************************************************/

        value_type data_field;
        node*      next_field;
};

#endif