// itertest.cc // Test BSTWithIter class // // Revision history // Removed const modifier from parameter of DisplayItem for compatability // with BST traversal procedures (12/5/98, RBL) #include #include "BSTiter.h" void DisplayItem(treeItemType & Item); int main() { BSTWithIter Tree1, Tree2; bool Success; treeItemType Item; // Build two trees with nodes containing 1 thru 10 for (int i = 1; i <= 10; ++i) { Item.SetKey(i*3%10+1); Tree1.SearchTreeInsert(Item, Success); Item.SetKey(i*7%10+1); Tree2.SearchTreeInsert(Item, Success); } // Preorder traversals of the two trees to see that they are different cout << "Preorder list of nodes in Tree 1: "; Tree1.PreorderTraverse(DisplayItem); cout << endl; cout << "Preorder list of nodes in Tree 2: "; Tree2.PreorderTraverse(DisplayItem); cout << endl << endl; // Inorder traversals of the two trees to see that they are ordered cout << "Inorder list of nodes in Tree 1: "; Tree1.InorderTraverse(DisplayItem); cout << endl; cout << "Inorder list of nodes in Tree 2: "; Tree2.InorderTraverse(DisplayItem); cout << endl << endl; //Now do the traversals with iterators cout << "Iterator traversal of Tree 1: "; for (BSTWithIter::iterator iter = Tree1.begin(); iter != Tree1.end(); ++iter) DisplayItem(*iter); cout <