// File: p5main1.cpp // // Tests ZoomTable functionality. // #include #include "ZoomTable.H" using namespace std ; void PrintNode(Node* ptr) { if (ptr == NULL) { cout << "NULL!!! " ; } else { cout << "(" << ptr->row() << "," << ptr->col() << ")=" << ptr->get() << "\n" ; } } int main() { ZoomTable Z(5,7,0) ; Node *ptr ; cout << "Z has " << Z.rows() << " rows and " << Z.cols() << " columns.\n\n" ; // After these insertions and deletions, the ZoomTable // should look like the diagram in the project description. Z.insert(0,5,41) ; Z.insert(0,6,42) ; Z.insert(0,4,43) ; Z.insert(0,0,44) ; Z.remove(0,5) ; Z.insert(1,3,45) ; Z.insert(1,4,46) ; Z.insert(4,6,47) ; Z.insert(2,1,48) ; Z.insert(2,4,49) ; Z.insert(3,5,27) ; Z.insert(2,5,50) ; Z.insert(3,0,51) ; Z.insert(4,0,52) ; Z.insert(3,3,17) ; Z.insert(1,6,54) ; Z.insert(4,4,37) ; Z.insert(3,3,56) ; ptr = Z.find(2,4) ; Z.remove(ptr) ; ptr = Z.find(3,5) ; ptr->set(49) ; Z.insert(4,4,55) ; Z.dump() ; cout << "\n\nNumber Check:\n" ; ptr = Z.FirstInCol(5) ; cout << ptr->get() << " == 50?\n" ; cout << Z.at(4,6) << " == 47?\n" ; cout << Z.at(3,3) << " == 56?\n" ; cout << Z.at(4,4) << " == 55?\n" ; cout << "\n\nTake a tour of the table:\n" ; ptr = Z.FirstInRow(2) ; PrintNode(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomDown(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomLeft(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomUp(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomDown(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomLeft(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomLeft(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomUp(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomUp(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; cout << "\n\nTake another tour of the table:\n" ; ptr = Z.FirstInCol(5) ; PrintNode(ptr) ; ptr = Z.ZoomDown(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomLeft(ptr) ; PrintNode(ptr) ; ptr = Z.ZoomUp(ptr) ; PrintNode(ptr) ; cout << "\n\nCheck some other functionality:\n" ; cout << "(Should see 7 NULLS)\n" ; ptr = Z.find(4,3) ; PrintNode(ptr) ; ptr = Z.find(2,1) ; ptr = Z.ZoomUp(ptr) ; PrintNode(ptr) ; ptr = Z.find(2,1) ; ptr = Z.ZoomLeft(ptr) ; PrintNode(ptr) ; ptr = Z.find(2,1) ; ptr = Z.ZoomDown(ptr) ; PrintNode(ptr) ; ptr = Z.find(2,1) ; ptr = Z.ZoomRight(ptr) ; ptr = Z.ZoomRight(ptr) ; PrintNode(ptr) ; ptr = Z.FirstInCol(2) ; PrintNode(ptr) ; Z.remove(2,1) ; Z.remove(2,5) ; ptr = Z.FirstInRow(2) ; PrintNode(ptr) ; cout << "\n" ; }