#include #include typedef struct cvor{ int broj; struct cvor *levi,*desni; }Cvor; Cvor* dodaj(Cvor *p,int broj) { Cvor *novi; novi=(Cvor *)malloc(sizeof(Cvor)); novi->levi=NULL; novi->desni=NULL; novi->broj=broj; if(p==NULL) { return novi; } else { Cvor *pom1,*pom2; pom1=p; while(pom1) { pom2=pom1; if(brojbroj) pom1=pom1->levi; else pom1=pom1->desni; } if(pom2->broj>broj) pom2->levi=novi; else pom2->desni=novi; return p; } } void padding ( char ch, int n ) { int i; for ( i = 0; i < n; i++ ) putchar ( ch ); } void structure ( struct cvor *root, int level ) { int i; if ( root == NULL ) { padding ( '\t', level ); puts ( "~" ); } else { structure ( root->desni, level + 1 ); padding ( '\t', level ); printf ( "%d\n", root->broj ); structure ( root->levi, level + 1 ); } } int BrojCvorovaUStablu(Cvor *koren, int *flag) { if (koren == NULL || *flag == 1) return 0; int l = BrojCvorovaUStablu(koren->levi, flag); int d = BrojCvorovaUStablu(koren->desni, flag); if (l != d) *flag = 1; return l + d + 1; } int JeIdealnoStablo(Cvor *koren) { int flag = 0; int brojCvorovaUStablu = BrojCvorovaUStablu(koren, &flag); if (flag == 1) return 0; return 1; } int main() { Cvor *koren=NULL; int n; scanf("%d",&n); int i; int broj; for(i=0;i