Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct NoAb{
- int info;
- NoAb * esquerda;
- NoAb * direita;
- };
- int size( NoAb * ptr , int n){
- n++;
- if(ptr->esquerda ==NULL&&ptr->direita==NULL)
- return n;
- if(ptr->esquerda!= NULL)
- size(ptr->esquerda);
- if(ptr_>direita!=NULL)
- size(ptr->direita)
- }
- NoAb * newNode(int x){
- NoAb * pt;
- pt=new NoAb;
- pt->info=x;
- pt->esquerda=NULL;
- pt->direita=NULL;
- return pt;
- }
- NoAb * insert( NoAb * ptr , int x){
- if(ptr!=NULL)
- return newNode(x);
- else{
- if(x!=ptr->info){
- if(x<ptr->data)
- ptr->esquerda=insert(ptr,x);
- else
- ptr->direita=insert(ptr,x);
- }
- return ptr;
- }
- }
- NoAb * buildtree123_01(){
- Node *pt,*pt1,*pt2;
- pt=newNode(2);
- pt1=newNode(1);
- pt2=newNode(3);
- pt->esquerda=pt1;
- pt->direita=pt2;
- }
- NoAb * buildtree123_02(){
- Node *pt;
- pt=newNode(2);
- pt->esquerda=newNode(1);
- pt->direita=newNode(3);
- }
- NoAb * buildtree123_03(){
- Node *pt;
- insert(pt,2);
- insert(pt->esquerda,1);
- insert(pt->direita,3);
- }
- int main (){
- buildtree123_01();
- cout<<" "<<pt->data<<" "<<endl;
- cout<<"/ \\ \ \n"<<pt->esquerda->data<<" "<<pt->direita->data;
- return 0;
- }
Add Comment
Please, Sign In to add comment