// FILE: list2.h
// CLASS PROVIDED: List (a container class for a List of items,
// where each List may have a designated item called the current item)
//
// TYPEDEF and MEMBER CONSTANTS for the List class:
//   static const int CAPACITY = ____ 
//     List::CAPACITY is the maximum number of items that a List can hold.
//     ** ignored in the case of linked list implementation **
//
//   typedef ____ Item
//     List::Item is the data type of the items in the List. It may be any of
//     the C++ built-in types (int, char, etc.), or a class with a default
//     constructor, an assignment operator, and a copy constructor.
//     for example, "typedef float Item" will make "Item" a new type which
//     in reality would be the same as "float".
//
// CONSTRUCTOR for the List class:
//   List( )
//     Postcondition: The List has been initialized as an empty List.
//
// MODIFICATION MEMBER FUNCTIONS for the List class:
//   void start( )
//     Postcondition: The first item on the List becomes the current item
//     (but if the List is empty, then there is no current item).
//
//   void advance( )
//     Precondition: is_item returns true.
//     Postcondition: If the current item was already the last item on the
//     List, then there is no longer any current item. Otherwise, the new
//     current item is the item immediately after the original current item.
//
//   void insert(const Item& entry)
//     Precondition: size( ) < CAPACITY.
//     Postcondition: A new copy of entry has been inserted in the List before
//     the current item. If there was no current item, then the new entry has 
//     been inserted at the front of the List. In either case, the newly
//     inserted item is now the current item of the List.
//
//   void attach(const Item& entry)
//     Precondition: size( ) < CAPACITY.
//     Postcondition: A new copy of entry has been inserted in the List after
//     the current item. If there was no current item, then the new entry has 
//     been attached to the end of the List. In either case, the newly
//     inserted item is now the current item of the List.
//
//   void remove_current( )
//     Precondition: is_item returns true.
//     Postcondition: The current item has been removed from the List, and the
//     item after this (if there is one) is now the new current item.
//
// CONSTANT MEMBER FUNCTIONS for the List class:
//   int size( ) const
//     Postcondition: The return value is the number of items on the List.
//
//   bool is_item( ) const
//     Postcondition: A true return value indicates that there is a valid
//     "current" item that may be retrieved by activating the current
//     member function (listed below). A false return value indicates that
//     there is no valid current item.
//
//   Item current( ) const
//     Precondition: is_item( ) returns true.
//     Postcondition: The item returned is the current item on the List.
//
// VALUE SEMANTICS for the List class:
//    Assignments and the copy constructor may be used with List objects.

#ifndef LIST2_H
#define LIST2_H
#include <stdlib.h>  

    typedef double Item;  // list will store "double"
    
    // objects of class Node will be linked to form the singly linked
    // list chain.
    class Node
    {
    public:
        Node() { this->next = NULL; };
        Node(const Item& entry)
        {
          this->data = entry; 
          this->next = NULL;
        };
        
        Item  getData() { return this->data; };
        void  setData(const Item& entry) {this->data = entry; };
        Node* getNext() { return this->next;};
        void  setNext( Node* value ) { this->next = value; };
    private:
        Item data;
        Node* next;
    };
    class List
    {
    public:
        // TYPEDEF and MEMBER CONSTANTS
        static const int CAPACITY = 30;
        // CONSTRUCTOR
        List( );
        // MODIFICATION MEMBER FUNCTIONS
        void start( );
        void advance( );
        void insert(const Item& entry);
        void attach(const Item& entry);
        void remove_current( );
        // CONSTANT MEMBER FUNCTIONS
        int size( ) const;
        bool is_item( ) const;
        Item current( ) const;
    private:
        Node* head;    // points to the first node in the list
        Node* cursor;  // points to current node
        Node* precursor; // points to node one before the current
        int count;     // count of nodes in the list;
    };

#endif
