int main() { int select = -1; Tree tree; while (true) { cout << "0: Exit" << endl; cout << "1: Add" << endl; cout << "2: Search" << endl; cout << "3: Load Preset Tree" << endl; cout << "4: Print" << endl; cin >> select; if (select == 0) return 0; if (select == 1) tree.EnterID(); if (select == 2) tree.Search(); if (select == 3) tree.Preset(); if (select == 4) tree.Print(); } }
int main(){ Tree t; (t.Root) = new node; t.Root->value=8; t.Root->parent = t.Root; //Initialize Full Tree t.Add(8); t.New(4,*((t.Root)),0); t.New(2,(*(t.Root)->L),0); t.New(6,(*(t.Root)->L),1); t.New(12,*((t.Root)),1); t.New(10,(*(t.Root)->R),0); t.New(14,(*(t.Root)->R),1); t.New(1,(*(t.Root)->L->L),0); t.New(3,(*(t.Root)->L->L),1); t.New(5,(*(t.Root)->L->R),0); t.New(7,(*(t.Root)->L->R),1); t.New(9,(*(t.Root)->R->L),0); t.New(11,(*(t.Root)->R->L),1); t.New(13,(*(t.Root)->R->R),0); t.New(15,(*(t.Root)->R->R),1); cout<<"\n# Original Tree :"<< endl; t.DisplayTree(); avg_num=0; avg_total=0; //Search Operations for (int i=15;i>0;i--){ t.Search(i); } int avg_total1 = avg_total; int avg_num1 = avg_num; avg_total=0; avg_num=0; //Delete Operations t.Delete(15); t.Delete(14); t.Delete(4); t.Delete(5); t.Delete(1); cout<<"\nAverage Rotations for Search Operation:"<<(float)avg_total1/avg_num1; cout<<"\nAverage Rotations for Delete Operation:"<<(float)avg_total/avg_num; // int a; // cout<< "Root :"; // t.DisplayNode( *(t.Root)); // node* m =(t.Root); // while(1){ // cout<<endl<<"Enter Selection :"; // cin>>a; // if(a==1){ // cout<<"Add :"; // cin>>a; // t.Add(a); // m =(t.Root); // } // else if(a==2){//Delete // cout<<"Delete :"; // cin>>a; // t.Delete(a); // m =(t.Root); // } // else if(a==3){//Current // t.DisplayNode(*m); // } // else if(a==4){//Root // cout<<"Root :"; // t.DisplayNode( *(t.Root)); // } // else if(a==5){//Left // m=(*m).L; // t.DisplayNode( *(m)); // } // else if(a==6){//Right // m=(*m).R; // t.DisplayNode( *(m)); // } // else if(a==7){//Up // m=(*m).parent; // t.DisplayNode( *(m)); // } // // // } }
#include <tree.cpp> #include <catch.hpp> #include <fstream> #include <iostream> using namespace std; SCENARIO("Insert_int", "[add]"){ Tree<int> tree; REQUIRE(tree.Insert(7)); REQUIRE(tree.Insert(3)); REQUIRE(tree.Insert(5)); REQUIRE(tree.Search(3)); REQUIRE(tree.Search(5)); REQUIRE(tree.Search(7)); } SCENARIO("Insert_char", "[add_c]"){ Tree<char> tree; REQUIRE(tree.Insert(5)); REQUIRE(tree.Insert(4)); REQUIRE(tree.Insert(6)); REQUIRE(tree.Search(4)); REQUIRE(tree.Search(5)); REQUIRE(tree.Search(6)); } SCENARIO("Insert_double", "[add_d]"){ Tree<double> tree; REQUIRE(tree.Insert(7.62)); REQUIRE(tree.Insert(3.14)); REQUIRE(tree.Insert(5.85));