Acasa Tehnologie Creare arbore binar

Creare arbore binar

by Dragos Schiopu
#include 

#include 

#include 

#include 


struct arb

{

  int info;

  struct arb *st,*dr;

}*arbore;



void creare(arb * aux, int as)

{

 arb * ax;


 if(asinfo)

   if(aux->st) creare(aux->st,as);

   else

     {

       ax=(arb *)malloc(sizeof(arb));

       ax->info=as;

       ax->st=NULL;

       ax->dr=NULL;

       aux->st=ax;

     }

 if(as>aux->info)

   if(aux->dr) creare(aux->dr,as);

   else

    {

       ax=(arb *)malloc(sizeof(arb));

       ax->info=as;

       ax->st=NULL;

       ax->dr=NULL;

       aux->dr=ax;

    }

}


void srd(arb *aux)

{

 if(aux->st) srd(aux->st);

 cout<info<<"  ";

 if(aux->dr) srd(aux->dr);

}


void main()

{

int a;

arbore=NULL;

//cout<<"Dati valoare";

//cin>>a;

arbore->info=3;

arbore->st=NULL;

arbore->dr=NULL;


creare(arbore,2);

creare(arbore,4);

srd(arbore);

getch();

}

s-ar putea sa-ti placa