text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

Table Class Reference

#include <TableA.h>

List of all members.


Detailed Description

ADT table. Sorted array-based implementation. Assumption: A table contains at most one item with a given search key at any time.

Definition at line 31 of file TableA.h.

Public Member Functions

 Table ()
virtual ~Table ()
virtual bool tableIsEmpty () const
virtual int tableLength () const
virtual void tableInsert (const TableItemType &newItem) throw (TableException)
virtual void tableDelete (KeyType searchKey) throw (TableException)
virtual void tableRetrieve (KeyType searchKey, TableItemType &tableItem) const throw (TableException)
virtual void traverseTable (FunctionType visit)

Protected Member Functions

void setSize (int newSize)
void setItem (const TableItemType &newItem, int index)
int position (KeyType searchKey) const

Private Member Functions

int keyIndex (int first, int last, KeyType searchKey) const

Private Attributes

TableItemType items [MAX_TABLE]
int size


Constructor & Destructor Documentation

Table::Table  ) 
 

Default constructor.

virtual Table::~Table  )  [virtual]
 


Member Function Documentation

virtual bool Table::tableIsEmpty  )  const [virtual]
 

Determines whether a table is empty.

Returns:
True if the table is empty; otherwise returns false.

virtual int Table::tableLength  )  const [virtual]
 

Determines the length of a table.

Returns:
The number of items in the table.

void Table::tableInsert const TableItemType newItem  )  throw (TableException) [virtual]
 

Inserts an item into a table in its proper sorted order according to the item's search key.

Precondition:
The item to be inserted into the table is newItem, whose search key differs from all search keys presently in the table.
Postcondition:
If the insertion is successful, newItem is in its proper order in the table.
Exceptions:
TableException If the item cannot be inserted.

Definition at line 22 of file TableA.cpp.

References MAX_TABLE.

void Table::tableDelete KeyType  searchKey  )  throw (TableException) [virtual]
 

Deletes an item with a given search key from a table.

Precondition:
searchKey is the search key of the item to be deleted.
Postcondition:
If the item whose search key equals searchKey existed in the table, the item is deleted.
Exceptions:
TableException If the item does not exist.

Definition at line 44 of file TableA.cpp.

void Table::tableRetrieve KeyType  searchKey,
TableItemType tableItem
const throw (TableException) [virtual]
 

Retrieves an item with a given search key from a table.

Precondition:
searchKey is the search key of the item to be retrieved.
Postcondition:
If the retrieval is successful, tableItem contains the retrieved item.
Exceptions:
TableException If the item does not exist.

Definition at line 65 of file TableA.cpp.

void Table::traverseTable FunctionType  visit  )  [virtual]
 

Traverses a table in sorted search-key order, calling function visit() once for each item.

Precondition:
The function represented by visit() exists outside of the ADT implementation.
Postcondition:
visit()'s action occurs once for each item in the table.
Note:
visit() can alter the table.

Definition at line 81 of file TableA.cpp.

References items, and size.

void Table::setSize int  newSize  )  [protected]
 

Sets the private data member size to newSize.

void Table::setItem const TableItemType newItem,
int  index
[protected]
 

Sets items[index] to newItem.

int Table::position KeyType  searchKey  )  const [protected]
 

Finds the position of a table item or its insertion point.

Precondition:
searchKey is the value of the search key sought in the table.
Returns:
The index (between 0 and size - 1) of the item in the table whose search key equals searchKey. If no such item exists, returns the position (between 0 and size) that the item would occupy if inserted into the table. The table is unchanged.

int Table::keyIndex int  first,
int  last,
KeyType  searchKey
const [private]
 

Searches a particular portion of the private array items for a given search key by using a binary search.

Precondition:
0 <= first, last < MAX_TABLE, where MAX_TABLE = max size of the array, and the array items[first..last] is sorted in ascending order by search key.
Returns:
If searchKey is in the array, returns the index of the array element that contains searchKey; otherwise returns the index (between first and last) of the array element that the item would occupy if inserted into the array in its proper order. The array is unchanged.


Member Data Documentation

TableItemType Table::items[MAX_TABLE] [private]
 

Table items.

Definition at line 110 of file TableA.h.

Referenced by traverseTable().

int Table::size [private]
 

Table size.

Definition at line 112 of file TableA.h.

Referenced by traverseTable().


The documentation for this class was generated from the following files:

Generated on Sun Aug 27 22:04:01 2006 for AWLogo by  doxygen 1.4.6