SHARE
TWEET

BSTmain

michalkowalczyk Mar 21st, 2019 53 in 150 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include<libraryBST.cpp>
  3.  
  4. int main()
  5. {
  6.     std::unique_ptr<bst::node> head;
  7.  
  8.     //Build a tree
  9.     head = bst::InsertNode(std::move(head),10);
  10.     head = bst::InsertNode(std::move(head),2);
  11.     head = bst::InsertNode(std::move(head),4);
  12.     head = bst::InsertNode(std::move(head),12);
  13.     head = bst::InsertNode(std::move(head),11);
  14.     head = bst::InsertNode(std::move(head),7);
  15.     head = bst::InsertNode(std::move(head),15);
  16.     head = bst::InsertNode(std::move(head),14);
  17.     head = bst::InsertNode(std::move(head),8);
  18.     head = bst::InsertNode(std::move(head),1);
  19.  
  20.  
  21.  
  22.  
  23.     //Printing tree in different ways
  24.     std::cout<<"Inorder"<<std::endl;
  25.     bst::PrintTreeInOrder(head);
  26.  
  27.     std::cout<<std::endl<<"Preorder"<<std::endl;
  28.     bst::PrintTreePreOrder(head);
  29.  
  30.     std::cout<<std::endl<<"Postorder"<<std::endl;
  31.     bst::PrintTreePostOrder(head);
  32.  
  33.     std::cout<<std::endl<<std::endl;
  34.  
  35.  
  36.     //Destroying tree
  37.     std::string destroyedTree = bst::DumpTree(head);
  38.  
  39.     std::cout<<"It's destroyed binary search tree: "<<std::endl;
  40.     std::cout<<destroyedTree<<std::endl;
  41.  
  42.      //Restoring tree
  43.     std::cout<<std::endl<<std::endl;
  44.     std::unique_ptr<bst::node> renew_tree ;
  45.     renew_tree = bst::RestoreTree(destroyedTree);
  46.  
  47.     //Printing restoried tree inorder
  48.     std::cout<<"Inorder - restoreTree"<<std::endl;
  49.     bst::PrintTreeInOrder(renew_tree);
  50.  
  51.  
  52.  
  53.  
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top