Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct tree{
- int val;
- tree* ltree;
- tree* rtree;
- };
- tree* crea(tree* t,int n){
- char c;
- while(t!=NULL){
- cout << "vuoi inserire a sx o a dx (s/d) ?\n";
- cin >> c;
- if(c=='s')
- t = t->ltree;
- else
- t = t->rtree;
- }
- t = new tree;
- t->val = n;
- t->ltree = NULL;
- t->rtree = NULL;
- return(t);
- }
- void stampa(tree* t){
- if(t!=NULL){
- cout << t->val;
- stampa(t->ltree);
- stampa(t->rtree);
- }
- }
- int main(){
- tree* t = NULL;
- int i,n;
- for(i=0;i<5;i++){
- cout << "inserisci un numero ";
- cin >> n;
- t=crea(t,n);
- }
- stampa(t);
- }
Add Comment
Please, Sign In to add comment