Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include "BST.h"
- using namespace std;
- main()
- {
- //prepara un albero iniziale non triviale
- nodo* r=new nodo(15, new nodo(7), new nodo(19));
- r->left->right=new nodo (9, new nodo(8));
- r->right->right=new nodo(25, new nodo(22));
- cout<<"start"<<endl;
- int x = -1;
- int y;
- bool stop=false;
- while(!stop)
- {
- cin>>x;
- if(x == 0){
- stop = true;
- }
- if(x == 1){
- stampa_l(r);
- cout<<endl;
- }
- if(x == 2){
- cin>>y;
- insert(r, y);
- stampa_l(r);
- cout<<endl;
- }
- if(x == 3){
- cin>>y;
- if(search(r, y)){
- cout<<"valore "<<y<<" presente"<<endl;
- }else{
- cout<<"valore "<<y<<" non presente"<<endl;
- }
- }
- if(x == 4){
- cin>>y;
- if(y == 1){
- nodo* massimo = max(r);
- cout<<massimo->info<<endl;
- }else{
- nodo* minimo = min(r);
- cout<<minimo->info<<endl;
- }
- }
- if(x == 5){
- int h = altezza(r);
- cout<<h<<endl;
- }
- if(x == 6){
- int altM = altMin(r);
- cout<<altM<<endl;
- }
- if(x == 7){
- cin>>y;
- elim(r, y);
- stampa_l(r);
- cout<<endl;
- }
- }
- cout<<"end"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment