// Provided by: Darin Gillis 349-70-0453 // Email Address: gillisd@colorado.edu // 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 long DEFAULT_CAPACITY = _____ // List::DEFAULT_CAPACITY is the initial capacity of a List that is // created by the default constructor. // // 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. // // CONSTRUCTOR for the List class: // List(long initial_capacity = DEFAULT_CAPACITY) // Postcondition: The List has been initialized as an empty List. // The insert/attach functions will work efficiently (without allocating // new memory) until this capacity is reached. // // MODIFICATION MEMBER FUNCTIONS for the List class: // void resize(long new_capacity) // Postcondition: The List's current capacity is changed to the // new_capacity (but not less that the number of items already on the // list). The insert/attach functions will work efficiently (without // allocating new memory) until this new capacity is reached. // // 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) // 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) // 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: // long 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. // // DYNAMIC MEMORY USAGE by the List // If there is insufficient dynamic memory, then the following functions // call new_handler: The constructors, insert, attach. #ifndef LIST2_H #define LIST2_H #include "race.h" class List { public: // TYPEDEF and MEMBER CONSTANTS static const long DEFAULT_CAPACITY = 6; typedef Race Item; // CONSTRUCTORS and DESTRUCTOR List(long initial_capacity = DEFAULT_CAPACITY); List(const List& source); ~List(); // MODIFICATION MEMBER FUNCTIONS void start(); void advance(); void insert(const Item& entry); void attach(const Item& entry); void remove_current(); void resize(long new_capacity); void operator =(const List& source); // CONSTANT MEMBER FUNCTIONS long size() const; bool is_item() const; Item current() const; private: Item *data; // the pointer to the dynamic array long used; // the number of array slots being used long capacity; // the complete size of the dynamic array long curpos; // current position (index #) }; #endif