//******************************************************************
// SPECIFICATION FILE (slist.h)
// This file gives the specification of a sorted list abstract data
// type. The list components are maintained in ascending order
// of value
//******************************************************************
const int MAX_LENGTH = 200; // Maximum possible number of
// components needed
// Requirement:
// MAX_LENGTH <= INT_MAX/2
#include
using namespace std;
typedef string ItemType; // Type of each component
// (a simple type or string class)
class SortedList
{
public:
bool IsEmpty() const;
// Postcondition:
// Function value == true, if list is empty
// == false, otherwise
bool IsFull() const;
// Postcondition:
// Function value == true, if list is full
// == false, otherwise
int Length() const;
// Postcondition:
// Function value == length of list
void Insert( /* in */ ItemType item );
// Precondition:
// NOT IsFull()
// && item is assigned
// Postcondition:
// item is in list
// && Length() == Length()@entry + 1
// && List components are in ascending order of value
void Delete( /* in */ ItemType item );
// Precondition:
// NOT IsEmpty()
// && item is assigned
// Postcondition:
// IF item is in list at entry
// First occurrence of item is no longer in list
// && Length() == Length()@entry - 1
// && List components are in ascending order of value
// ELSE
// List is unchanged
bool IsPresent( /* in */ ItemType item ) const;
// Precondition:
// item is assigned
// Postcondition:
// Function value == true, if item is in list
// == false, otherwise
void Print() const;
// Postcondition:
// All components (if any) in list have been output
SortedList();
// Constructor
// Postcondition:
// Empty list is created
private:
int length;
ItemType data[MAX_LENGTH];
void BinSearch( ItemType, bool&, int& ) const;
};