//****************************************************************** // SPECIFICATION FILE (SortedList.h) // This file gives the specification of a SortedList abstract data // type. The components are assumed to be in order by value. // To save space, we omit from each function the precondition // comments that document the assumptions made about valid input // parameter data. These would be included in a program intended // for actual use. //****************************************************************** const int MAX_LENGTH =100; // Maximum possible number of // components needed typedef int ItemType; // Type of each component // (a simple type or string class) class SortedList { public: bool IsEmpty() const; // Postcondition: // Return value == true, if SortedList is empty // == false, otherwise bool IsFull() const; // Postcondition: // Return value == true, if SortedList is full // == false, otherwise int Length() const; // Postcondition: // Return value == length of SortedList void Insert( /* in */ ItemType& item ); // Inserts item into the SortedList // Precondition: // length < MAX_LENGTH // && data[0..length-1] are in ascending order // Postcondition: // item is in the SortedList // && length == length@entry + 1 // && data[0..length-1] are in ascending order void Delete( /* in */ ItemType item ); // Precondition: // NOT IsEmpty() // Postcondition: // IF item is in SortedSortedList at entry // First occurrence of item is no longer // in SortedList // && Length() == Length()@entry - 1 // ELSE // SortedList is unchanged bool IsPresent( /* in */ ItemType item ) const; // Precondition: // Postcondition: // Return value == true, if item is in SortedList // == false, otherwise void Reset(); // Postcondition: // Iteration is initialized ItemType GetNextItem(); // Precondition: // No transformers have been invoked since last call // Postcondition: // Returns item at the current position in the // SortedList SortedList(); // Constructor // Postcondition: // Empty SortedList is created private: int length; int currentPos; ItemType data[MAX_LENGTH]; void BinSearch( ItemType, bool&, int& ) const; };