![]() |
Data Abstraction and Problem Solving with C++Walls and Mirrorsby Frank M. Carrano |
![]() |
TableA.hGo to the documentation of this file.00001 00017 #include "KeyedItem.h" // definition of KeyedItem 00018 // and KeyType 00019 #include "TableException.h" 00020 00021 const int MAX_TABLE = maximum-size-of-table; 00022 00023 typedef KeyedItem TableItemType; 00024 typedef void (*FunctionType)(TableItemType& anItem); 00025 00031 class Table 00032 { 00033 public: 00035 Table(); 00036 // copy constructor is supplied by the compiler 00037 virtual ~Table(); 00039 // Table operations: 00040 // Precondition for all operations: 00041 // No two items of the table have the same search key. 00042 // The table's items are sorted by search key. 00043 00047 virtual bool tableIsEmpty() const; 00048 00051 virtual int tableLength() const; 00052 00061 virtual void tableInsert(const TableItemType& newItem) 00062 throw(TableException); 00063 00069 virtual void tableDelete(KeyType searchKey) 00070 throw(TableException); 00071 00078 virtual void tableRetrieve(KeyType searchKey, 00079 TableItemType& tableItem) const 00080 throw(TableException); 00081 00089 virtual void traverseTable(FunctionType visit); 00090 00091 protected: 00093 void setSize(int newSize); 00094 00096 void setItem(const TableItemType& newItem, int index); 00097 00106 int position(KeyType searchKey) const; 00107 00108 private: 00110 TableItemType items[MAX_TABLE]; 00112 int size; 00113 00125 int keyIndex(int first, int last, KeyType searchKey) const; 00126 00127 }; // end Table 00128 // End of header file. |