// // File: demo_main.C // Author: Chuck Stewart // // Purpose: To demonstrate use of an AVL tree through insert and // remove operations. // // The simple text output is a rotated version of the tree with the // right subtree printed on top. This is an inorder traversal with // right subtrees printed first instead of left subtrees. Each node // in the tree is printed on a single line and is indented according // to its depth. To get a feel for ``visualizing'' the printed // trees, draw a picture of trees after they are printed. // #define DEMO #include using namespace std; #include "BSTree.h" void main() { BSTree< int > int_tree( true ); cout << "\nSimple program with text output to demonstrate insert and\n" << "remove operations on an AVL tree. The output is a rotated\n" << "version of the tree with the right subtree printed on top.\n" << "This is an inorder traversal with right subtrees printed.\n" << "first instead of left subtrees. Each node in the tree is\n" << "printed on a single line and is indented according to its depth.\n" << "To get a feel for ``visualizing'' the printed trees, draw a\n" << "picture of the trees after they are printed.\n\n"; char command; int value; do { cout << "Enter i (insert) and an int, r (remove) and an int, or q ==> "; cin >> command; if ( command == 'i' || command == 'I' ) { cin >> value; int_tree.Insert( value ); cout << "\n\n"; int_tree.Print_Tree( ); cout << "\n\n"; } else if ( command == 'r' || command == 'R' ) { cin >> value; int_tree.Remove( value ); cout << "\n\n"; int_tree.Print_Tree( ); cout << "\n\n"; } else break; } while( 1 ); cout << "\n\nFinal tree height: " << int_tree.Height() << "\n"; }