SamuelKostadinov

Untitled

Jun 3rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include<iostream>
  2. #include "BST.h"
  3. using namespace std;
  4. main()
  5. {
  6.     //prepara un albero iniziale non triviale
  7.   nodo* r=new nodo(15, new nodo(7), new nodo(19));
  8.   r->left->right=new nodo (9, new nodo(8));
  9.   r->right->right=new nodo(25, new nodo(22));
  10.  
  11.   cout<<"start"<<endl;
  12.   int x = -1;
  13.   int y;
  14.   bool stop=false;
  15.  
  16.   while(!stop)
  17.     {
  18.         cin>>x;
  19.         if(x == 0){
  20.             stop = true;
  21.         }
  22.         if(x == 1){
  23.             stampa_l(r);
  24.             cout<<endl;
  25.         }
  26.         if(x == 2){
  27.            cin>>y;
  28.            insert(r, y);
  29.            stampa_l(r);
  30.            cout<<endl;
  31.         }
  32.         if(x == 3){
  33.            
  34.             cin>>y;
  35.             if(search(r, y)){
  36.                 cout<<"valore "<<y<<" presente"<<endl;
  37.             }else{
  38.                 cout<<"valore "<<y<<" non presente"<<endl;
  39.             }
  40.            
  41.         }
  42.         if(x == 4){
  43.             cin>>y;
  44.             if(y == 1){
  45.                 nodo* massimo = max(r);
  46.                 cout<<massimo->info<<endl;
  47.             }else{
  48.                 nodo* minimo = min(r);
  49.                 cout<<minimo->info<<endl;
  50.             }
  51.         }
  52.         if(x == 5){
  53.             int h = altezza(r);
  54.             cout<<h<<endl;
  55.         }
  56.         if(x == 6){
  57.             int altM = altMin(r);
  58.             cout<<altM<<endl;
  59.         }
  60.         if(x == 7){
  61.             cin>>y;
  62.             elim(r, y);
  63.             stampa_l(r);
  64.             cout<<endl;
  65.         }
  66.     }
  67.    
  68.     cout<<"end"<<endl;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment