00001
00020 #include "TableA.h"
00021
00022 void Table::tableInsert(const TableItemType& newItem)
00023 throw(TableException)
00024
00025
00026
00027 {
00028 if (size == MAX_TABLE)
00029 throw TableException("TableException: Table full");
00030
00031
00032
00033 int spot = position(newItem.getKey());
00034
00035
00036 for (int index = size-1; index >= spot; --index)
00037 items[index+1] = items[index];
00038
00039
00040 items[spot] = newItem;
00041 ++size;
00042 }
00043
00044 void Table::tableDelete(KeyType searchKey)
00045 throw(TableException)
00046
00047 {
00048
00049 int spot = position(searchKey);
00050
00051
00052 if ((spot > size) || (items[spot].getKey() != searchKey))
00053
00054 throw TableException("TableException: Item not found on delete");
00055 else
00056 {
00057 --size;
00058
00059
00060 for (int index = spot; index < size; ++index)
00061 items[index] = items[index+1];
00062 }
00063 }
00064
00065 void Table::tableRetrieve(KeyType searchKey,
00066 TableItemType& tableItem) const
00067 throw(TableException)
00068
00069 {
00070
00071 int spot = position(searchKey);
00072
00073
00074 if ((spot > size) || (items[spot].getKey() != searchKey))
00075
00076 throw TableException("TableException: Item not found on retrieve");
00077 else
00078 tableItem = items[spot];
00079 }
00080
00081 void Table::traverseTable(FunctionType visit)
00082 {
00083 for (int index = 0; index < size; ++index)
00084 visit(items[index]);
00085 }
00086