struct element{ labeltype label; struct element *lijevi,*desni; }; typedef struct element *cvor; typedef struct element *tstablo; cvor ParentB(cvor n,tstablo stablo){ nod i; int OK=0; stack S; MakeNullS(S); PushS(stablo,S); while((!IsEmptyS(S)) && (!OK)){ i=PopS(S); if (i->lijevi!=n) && (i->desni!=n)){ if (i->lijevi!=NULL) PushS(i->l); if (i->desni!=NULL) PushS(i->d); else OK=-1; } if(OK) return i; else return NULL; } cvor LeftChildB(cvor n,tstablo stablo){ return n->lijevi; } cvor RightChildB(cvor n,tstablo stablo){ return n->desni; } labeltype LabelB(cvor n,tstablo stablo){ return n->label; } void ChangeLabelB(labeltype vrijednost, cvor n,tstablo stablo){ n->label=vrijednost; } cvor RootB(tstablo stablo){ return stablo; } void CreateLeftB(labeltype vrijednost,cvor n,tstablo stablo){ cvor l; if(n->lijevi!=NULL){ l=(struct element *)malloc(sizeof(struct element)); l->lijevi=l->desni=NULL; l->label=vrijednost; n->lijevi=l; } else return; } void CreateRightB(labeltype vrijednost,cvor n,tstablo stablo){ cvor l; if (n->desni!=NULL){ l=(struct element *)malloc(sizeof(struct element)); l->lijevi=l->desni=NULL; l->label=vrijednost; n->desni=l; } else return; } void DelB(cvor n, tstablo stablo){ if (n->lijevi!=NULL) DelB((n->lijevi,stablo); if (n->desni!=NULL) DelB((n->desni,stablo); free(n); } void DeleteB(cvor n,tstablo stablo){ cvor l; if (n->lijevi!=NULL) DelB((n->lijevi,stablo); if (n->desni!=NULL) DelB((n->desni,stablo); l=ParentB(n,stablo); if(l->lijevi==n) l->lijevi=NULL; else l->desni=NULL; free(n); } void InitB(cvor vrijednost, tstablo *stablo){ cvor l; l=(struct element *)malloc(sizeof(struct element)); l->lijevi=l->desni=NULL; l->label=vrijednost; (*stablo)=l; } //Razlike: Napravio sam samo implementaciju pomocu pokazivaca, vecina je radila implementaciju pomocu polja. Razlicite varijable.