// ********************************************************* // Excerpts from the implementation file TableA.cpp. // Sorted array-based implementation. // ********************************************************* #include "TableA.h" // header file void tableClass::TableInsert(const tableItemType& NewItem, bool& Success) // Note: Insertion is unsuccessful if the table is full, // that is, if the table already contains MAX_TABLE items. // Calls: Position. { // is there room for insertion? Success = bool(Size < MAX_TABLE); if (Success) { // there is room to insert; // locate the position where NewItem belongs int Spot = Position(NewItem.Key()); // shift up to make room for the new item for (int Index = Size-1; Index >= Spot; --Index) Items[Index+1] = Items[Index]; // make the insertion Items[Spot] = NewItem; ++Size; } // end if } // end TableInsert void tableClass::TableDelete(keyType SearchKey, bool& Success) // Calls: Position. { // locate the position where SearchKey exists/belongs int Spot = Position(SearchKey); // is SearchKey present in the table? Success = bool((Spot <= Size) && (Items[Spot].Key() == SearchKey)); if (Success) { // SearchKey in Table --Size; // delete the item // shift down to fill the gap for (int Index = Spot; Index < Size; ++Index) Items[Index] = Items[Index+1]; } // end if } // end TableDelete void tableClass::TableRetrieve(keyType SearchKey, tableItemType& TableItem, bool& Success) const // Calls: Position. { // locate the position where SearchKey exists/belongs int Spot = Position(SearchKey); // is SearchKey present in table? Success = bool((Spot <= Size) && (Items[Spot].Key() == SearchKey)); if (Success) TableItem = Items[Spot]; // item present; retrieve it } // end TableRetrieve void tableClass::TraverseTable(functionType Visit) { for (int Index = 0; Index < Size; ++Index) Visit(Items[Index]); } // end TraverseTable // End of implementation file.