//===============AFISARE INALTIME================= void inaltime(arb *r, int &h, int level) { if(r != NULL) { h = max(h, level++); inaltime(r->st, h, level); inaltime(r->dr, h, level); } }
int inaltime(arb *a){ int hs,hd; if(a){ hs = inaltime(a->st); hs = inaltime(a->st); if(hs>hd) return hs+=1; else return hd+=1; }else{ return 0; } }
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; }
int main(){ arb *a; a = creare(); printf("\nRSD:");RSD(a); printf("\nSRD:");SRD(a); printf("\nSDR:");SDR(a); printf("\nSuma:%d",suma(a)); printf("\nMaxim:%d",maxim(a)); printf("\nNr frunze:%d",frunze(a)); printf("\nInaltimea:%d",inaltime(a)); return 0; }