//===============PREORDINE================= void preordine(arb *r) { if(r != NULL) { printf("%d ", r->val); preordine(r->st); preordine(r->dr); } }
void preordine(Arb arb,int pas) { int i; if (arb!=NULL) { for (i=1;i<=pas;i++) printf("\t"); printf("%d\n",(*arb).val); preordine((*arb).st,pas+1); preordine((*arb).dr,pas+1); } }
int _tmain(int argc, _TCHAR* argv[]) { arb *rad; int h = 0, level = 0, search = 0; FILE *f = fopen("arb.txt", "r"); rad = (arb *)malloc(sizeof(arb)); citeste(f, *&rad); cout<<"PREORDINE: "; preordine(rad); cout<<endl<<endl; cout<<"INORDINE: "; inordine(rad); cout<<endl<<endl; cout<<"POSTORDINE: "; postordine(rad); cout<<endl<<endl; cout<<"FRUNZE: "; frunze(rad); cout<<endl<<endl; cout<<"INALTIME: "; inaltime(rad, h, 0); cout<<h<<" (radacina fiind pe nivelul 0)"<<endl<<endl; cout<<"ALEGE NIVELUL PE CARE VREI SA-L AFISEZI:"; cin>>level; cout<<"PE NIVELUL "<<level<<" SE GASESC NODURILE:"; afisareNivel(rad, level, 0); cout<<endl<<endl; free(rad); f = fopen("sir.txt", "r"); rad = (arb *)malloc(sizeof(arb)); rad->val = NULL;rad->st = NULL;rad->dr = NULL; cout<<"SIRUL CITIT: "; citesteArboreBinar(f, *&rad); cout<<endl<<"INTRODUCETI NUMARUL CAUTAT:"; cin>>search; level = cautaNumar(rad, search, 0); if(level == -1) { cout<<"NUMARUL NU A FOST GASIT"<<endl; } else { cout<<"NUMARUL A FOST GASIT PE NIVELUL "<<level<<endl; } free(rad); return 0; }