0% found this document useful (0 votes)
77 views4 pages

ARBORI

1. The document contains C++ code for implementing a binary search tree. It includes functions for inserting nodes, traversing the tree to print values, and calculating the height of the tree. 2. Additional code is provided to calculate the number of columns in the tree and draw the tree using graphics functions. It recursively draws each node as a star shape positioned based on level and column number. 3. The main function calls the tree drawing function, first calculating the number of levels, to display the binary search tree visually.

Uploaded by

Tibi Badelita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

ARBORI

1. The document contains C++ code for implementing a binary search tree. It includes functions for inserting nodes, traversing the tree to print values, and calculating the height of the tree. 2. Additional code is provided to calculate the number of columns in the tree and draw the tree using graphics functions. It recursively draws each node as a star shape positioned based on level and column number. 3. The main function calls the tree drawing function, first calculating the number of levels, to display the binary search tree visually.

Uploaded by

Tibi Badelita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

#include<iostream>

using namespace std;

struct nod {
int info;
nod *st;
nod *dr;
};

nod *arbore;

int n,k;

void inserare(nod *&c,int k)

{if(c)

if(c->info<k)

inserare(c->dr,k);

else

inserare(c->st,k);

else

{c=new nod;

c->info=k;

c->st=c->dr=0;}

void afis(nod *c)

{if(c)

cout<<c->info<<" ";

afis(c->st);

afis(c->dr);

}
int main()
{
int v[100];

cin>>n;

for(int i=1;i<=n;i++)
{cin>>v[i];
inserare(arbore,v[i]);}

afis(arbore);

return 0;
}

2.
#include <iostream>

using namespace std;

struct nod {
int info;
nod *st;
nod *dr;
};

nod *arbore;

void inserare(nod *&c,int k)

{if(c)

if(c->info<k)

inserare(c->dr,k);

else

inserare(c->st,k);

else

{c=new nod;

c->info=k;

c->st=c->dr=0;}

int h(nod *p, int k)


{
int a,b;

if((p->st==NULL)&&(p->dr==NULL)) return k;
else
{
a=h(p->st,k+1);
b=h(p->dr,k+1);

if(a>b) return a;
else
return b;
}
}

int main()
{
int x , n , k=0;

cout<<"numar de noduri:";
cin>>n;

for(int i=1;i<=n;i++)
{cin>>x;
inserare(arbore,x);}

cout<<"inaltimea este:"<<h(arbore , k);

return 0;
}

LAB 7 - inceput
#include <iostream>
#include <math.h>
#include <graphics.h>
#include <winbgim.h>

using namespace std;

struct nod{
int info;
nod *st, *dr;
};

nod *a;

int nrNiveluri(nod *a);


{
if(a==NULL)
return 0;
else
{int n1=nrNivelur(a->st);
int n2=nrNiveluri(a->dr);
return 1+max(n1,n2);}
}

int nrColoane(nod *a)


{
if(a==NULL)
return 0;
else
{
int n1=nrColoane(a->st);
int n2=nrColoane(a->dr);

return 1+n1+n2;
}
}

void desen(int inf , int niv , int nrc)


{
float beta = (2*3.14159625)/6;
float x[100], y[100] , l , c;

for(int i=0;i<=6;i++)
{x[i]=xc+R*cos(alfa+beta*i);
y[i]=yc+R*sin(alfa+beta*i);}

for(int i=0;i<6;i++)
line(x[i],y[i],x[i+1],y[i+1]);

void deseneaza(nod *a , int niv)


{
if(a!=NULL)
{desen(a->info, niv , 1+nrColoane(a->st));
deseneaza(a->st , niv + 1);
deseneaza(a->dr , niv + 1);
}

int main()
{
int niv;

niv=nrNiveluri(a);

deseneaza(a,1);

return 0;
}

You might also like