282
>
//Arbori (alocare dinamica) - parcurgerile RSD, SRD si SDR
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
struct arbore
{
int inf;
arbore *st,*dr;
}*r;
arbore *creare()
{
arbore *aux;
char c;
printf(" e nod nul?(SPACE pt da)");
c=getche();
if (c!=' ')
{
aux=(arbore *)malloc(sizeof(arbore));
printf("nDati valoare: ");
scanf("%d",&aux->inf);
printf("n fiul stang al lui %d",aux->inf);
aux->st=creare();
printf("n fiul drept al lui %d",aux->inf);
aux->dr=creare();
return aux;
}
else return NULL;
}
void SRD(arbore *r)
{
if (r)
{
SRD(r->st);
printf("%d ",r->inf);
SRD(r->dr);
}
}
void SDR(arbore *r)
{
if (r)
{
SDR(r->st);
SDR(r->dr);
printf("%d ",r->inf);
}
}
void RSD(arbore *r)
{
if (r)
{
printf("%d ",r->inf);
RSD(r->st);
RSD(r->dr);
}
}
void main()
{
clrscr();
printf("Radacina");
r=creare();
printf("nParcurgerea RSD: ");
RSD(r);
printf("nParcurgerea SRD: ");
SRD(r);
printf("nParcurgerea SDR: ");
SDR(r);
getch();
}