Guest User

Untitled

a guest
Jan 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct NoAb{
  5.   int info;
  6.   NoAb * esquerda;
  7.   NoAb  * direita;
  8.   };
  9.                                                        
  10. int size( NoAb * ptr , int n){
  11.   n++;
  12.   if(ptr->esquerda ==NULL&&ptr->direita==NULL)
  13.     return n;
  14.   if(ptr->esquerda!= NULL)
  15.       size(ptr->esquerda);
  16.   if(ptr_>direita!=NULL)
  17.       size(ptr->direita)
  18.  
  19. }
  20.  
  21.  
  22. NoAb * newNode(int x){
  23.   NoAb * pt;
  24.   pt=new NoAb;
  25.   pt->info=x;
  26.   pt->esquerda=NULL;
  27.   pt->direita=NULL;
  28.   return pt;
  29. }
  30.  
  31. NoAb * insert(  NoAb * ptr , int x){
  32.   if(ptr!=NULL)
  33.     return newNode(x);
  34.   else{
  35.     if(x!=ptr->info){
  36.       if(x<ptr->data)
  37.     ptr->esquerda=insert(ptr,x);
  38.       else
  39.     ptr->direita=insert(ptr,x);
  40.     }
  41.       return ptr;
  42.     }
  43.   }
  44.  
  45. NoAb * buildtree123_01(){
  46.   Node *pt,*pt1,*pt2;
  47.   pt=newNode(2);
  48.   pt1=newNode(1);
  49.   pt2=newNode(3);
  50.   pt->esquerda=pt1;
  51.   pt->direita=pt2;
  52. }
  53.  
  54. NoAb * buildtree123_02(){
  55.   Node *pt;
  56.   pt=newNode(2);
  57.   pt->esquerda=newNode(1);
  58.   pt->direita=newNode(3);
  59.  
  60. }
  61. NoAb * buildtree123_03(){
  62.   Node *pt;
  63.   insert(pt,2);
  64.   insert(pt->esquerda,1);
  65.   insert(pt->direita,3);
  66. }
  67.  
  68. int main (){
  69.  
  70.   buildtree123_01();
  71.   cout<<" "<<pt->data<<" "<<endl;
  72.   cout<<"/ \\ \ \n"<<pt->esquerda->data<<"  "<<pt->direita->data;
  73.   return 0;
  74. }
Add Comment
Please, Sign In to add comment