int main(){ BinarySearchTree bst; // The number of leaves that the tree will have int leaves; // Ask the user how many leaves does he wants cout << "How many numbers are you inserting? "; //store the value cin >> leaves; cout << endl; Node * root = NULL; //repeatthis statement the number of times the user will give a number for (int i = 0; i < leaves; i++) { //Ask the user for the number, and save it int number; cout << "Insert the number #" << i + 1 << endl; cin >> number; if(root == NULL){ root = new Node (number); bst.set_root(root); } else { bst.insert_integer(&root, number); } } cout << "No we will print the tree" << endl; bst.print_tree (bst.get_root()); //cout << "Now we will delete the tree" << endl; //bst.terminate_tree(bst.get_root()); int exit; cin >> exit; return 0; }
int main(int argc, const char *argv[]){ cout << "BST Traversals: " << endl; BinarySearchTree<int> tree; tree.Insert(5); tree.Insert(7); tree.Insert(9); tree.Insert(3); tree.Insert(2); tree.Insert(1); cout << "In Order: "; InOrder(tree.get_root()); cout << endl; cout << "Pre Order: "; PreOrder(tree.get_root()); cout << endl; cout << "Post Order: "; PostOrder(tree.get_root()); cout << endl; cout << "In Order Stack: "; InOrderStack(tree.get_root()); cout << endl; cout << "In Order Morris: "; InOrderMorris(tree.get_root()); cout << endl; cout << "Breadth First: "; BreadthFirst(tree.get_root()); cout << endl; cout << "Level Order: "; LevelOrder(tree.get_root()); cout << endl; cout << endl; cout << "AVL tree Traversals: " << endl; BinarySearchTree<int> avl; avl.Insert(5); avl.Insert(7); avl.Insert(9); avl.Insert(3); avl.Insert(2); avl.Insert(1); cout << "In Order: "; InOrder(avl.get_root()); cout << endl; cout << "Pre Order: "; PreOrder(avl.get_root()); cout << endl; cout << "Post Order: "; PostOrder(avl.get_root()); cout << endl; cout << "In Order Stack: "; InOrderStack(avl.get_root()); cout << endl; cout << "In Order Morris: "; InOrderMorris(avl.get_root()); cout << endl; cout << "Breadth First: "; BreadthFirst(avl.get_root()); cout << endl; cout << "Level Order: "; LevelOrder(avl.get_root()); cout << endl; return 0; }