int main(){ BST tree; //test 1 tree.insert(5,"ahmed"); tree.insert(7,"daramally"); tree.inOrder(); cout << "Current H :" << tree.getMaxHeight() << "\n"; cout << "\ntest 1 is successful!\n\n"; //test 2 tree.insert(1,"omar"); tree.inOrder(); cout << "Current H :" << tree.getMaxHeight() << "\n"; cout << "\ntest 2 is successful!\n\n"; //test 3 tree.set(7,"non-daramally"); cout << "Current H :" << tree.getMaxHeight() << "\n"; tree.inOrder(); cout << "\ntest 3 is successful!\n\n"; //test 4 tree.insert(2,"mostafa"); tree.insert(3,"todo"); tree.inOrder(); cout << "Current H :" << tree.getMaxHeight() << "\n"; cout << "\ntest 4 is successful!\n\n"; //test 5 tree.modify(3,"darsh"); cout << "Value after edit : " << tree.lookUp(3) << "\n"; tree.inOrder(); cout << "\ntest 5 is successful!\n\n"; //test 6 cout << "before delete\nContains key? : " << tree.containsKey(3) << "\n"; tree.deleteNode(3); cout << "after delete\nContains key? : " << tree.containsKey(3) << "\n"; tree.inOrder(); cout << "Current H :" << tree.getMaxHeight() << "\n"; cout << "\ntest 6 is successful!\n\n"; //test 7 cout << "Num of Nodes : " << tree.countNodes() << "\n"; tree.displayMin(); tree.displayMax(); puts(""); tree.preOrder(); puts(""); tree.postOrder(); cout << "\ntest 7 is successful!\n\n"; }
int main() { char restart; char selection; BST<string> p; string sentence = "George Samsa awoke one morning only to discover " "he had been transformed into a giant Cockroach"; istringstream iss(sentence); while(iss) { string word; iss >> word; p.Insert(strtolower(word)); } do{ cout << "a.\tDisplay the words in alphabetical order\n" << "b.\tdisplay the tree sideways\n" << "c.\tHow many leaves does the tree have\n" << "d.\tWhat is the height of the tree\n" << "e.\tSelect a random letter from a-z and delete all words that begin with that letter\n\n"; cout << "Make a selection: "; cin >> selection; switch(tolower(selection)) { case 'a': cout << "\nWords in alphabetical order: "; p.DispTree(); cout << endl; break; case 'b': p.DispSideway(); break; case 'c': cout << "\nNumber of leaves in tree: "; p.countNodes(); break; case 'd': cout << "\nHeight of tree: "; p.treeHeight(); break; } cout << "\nAgain(Y/N)?: "; cin >> restart; cout << endl; }while(toupper(restart) == 'Y'); return 0; }
int main() { BST<int> tree; cout << "Inserting: 5\n"; tree.insert(5); cout << "Inorder: "; tree.showInOrder(); cout << endl; cout << "Preorder: "; tree.showPreOrder(); cout << endl; cout << "Postorder: "; tree.showPostOrder(); cout << endl; cout << "***\n"; cout << "Inserting: 8\n"; tree.insert(8); cout << "Inorder: "; tree.showInOrder(); cout << endl; cout << "Preorder: "; tree.showPreOrder(); cout << endl; cout << "Postorder: "; tree.showPostOrder(); cout << endl; cout << "***\n"; cout << "Inserting: 3\n"; tree.insert(3); cout << "Inorder: "; tree.showInOrder(); cout << endl; cout << "Preorder: "; tree.showPreOrder(); cout << endl; cout << "Postorder: "; tree.showPostOrder(); cout << endl; cout << "***\n"; cout << "Inserting: 12\n"; tree.insert(12); cout << "Inorder: "; tree.showInOrder(); cout << endl; cout << "Preorder: "; tree.showPreOrder(); cout << endl; cout << "Postorder: "; tree.showPostOrder(); cout << endl; cout << "***\n"; cout << "Inserting: 9\n"; tree.insert(9); cout << "Inorder: "; tree.showInOrder(); cout << endl; cout << "Preorder: "; tree.showPreOrder(); cout << endl; cout << "Postorder: "; tree.showPostOrder(); cout << endl; system("pause"); system("cls"); cout << "Testing isExist:\n"; cout << "\tSearching for 10: " << (tree.isExists(10) ? "Found" : "Not Found") << endl; cout << "\tSearching for 12: " << (tree.isExists(12) ? "Found" : "Not Found") << endl; system("pause"); system("cls"); /////////////////////////// I added this code /////////////////////////// cout << "Testing countNodes:\n"; cout << setw(25) << "Number of nodes: " << tree.countNodes() << endl; cout << "Testing countLeaves:\n"; cout << setw(25) << "Number of leaves: " << tree.countLeaves() << endl; system("pause"); system("cls"); cout << "Testing height:\n"; cout << setw(25) << "Height: " << tree.height() << endl; system("pause"); system("cls"); cout << "Testing printPath:\n"; cout << "Path to 5: " << endl; tree.printPath(5); cout << endl; cout << "Path to 3: " << endl; tree.printPath(3); cout << endl; cout << "Path to 8: " << endl; tree.printPath(8); cout << endl; cout << "Path to 12: " << endl; tree.printPath(12); cout << endl; cout << "Path to 9: " << endl; tree.printPath(9); cout << endl; system("pause"); system("cls"); /////////////////////////// I added this code /////////////////////////// cout << "Testing remove:\n"; cout << setw(25) << "Original Tree: "; tree.showInOrder(); cout << endl; cout << setw(25) << "After Removing 12: "; tree.remove(12); tree.showInOrder(); cout << endl; cout << setw(25) << "After Removing 5: "; tree.remove(5); tree.showInOrder(); cout << endl; cout << setw(25) << "After Removing 1: "; tree.remove(1); tree.showInOrder(); cout << endl; system("pause"); return 0; }