// vector.h // declaration for array-based, unsorted list ADT implementation // based on listClass code in ListA.h from Carrano et al. #ifndef _VECTOR_H_ #define _VECTOR_H_ const int MAX_LIST = 128; // Replace listItemType with a type to yield a vector class that // stores items of that type. typedef char listItemType; class Vector { public: Vector(); // default constructor // destructor is supplied by compiler // list operations: bool IsEmpty() const; // Determines whether a list is empty. // Precondition: None. // Postcondition: Returns true if the list is empty, // otherwise returns false. int GetLength() const; // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items // that are currently in the list. void InsertItem(int NewPosition, listItemType NewItem, bool &Success); // Inserts an item into a list. // Precondition: NewPosition indicates where the // insertion should occur. NewItem is the item to be // inserted. // Postcondition: If insertion was successful, NewItem is // at position NewPosition in the list, other items are // renumbered accordingly, and Success is true; // otherwise Success is false. // Note: Insertion will not be successful if // NewPosition < 0 or > GetLength(). void DeleteItem(int Position, bool &Success); // Deletes an item from a list. // Precondition: Position indicates where the deletion // should occur. // Postcondition: If 0 <= Position < GetLength(), // the item at position Position in the list is // deleted, other items are renumbered accordingly, // and Success is true; otherwise Success is false. void RetrieveItem(int Position, listItemType &DataItem, bool &Success) const; // Retrieves a list item by position number. // Precondition: Position is the number of the item to // be retrieved. // Postcondition: If 0 <= Position < GetLength(), // DataItem is the value of the desired item and // Success is true; otherwise Success is false. private: listItemType Items[MAX_LIST]; // array of list items int Size; // number of items in list }; // end class // End of header file. #endif // _VECTOR_H_