/ Published in: C++
Expand |
Embed | Plain Text
struct Cvor{ int Label; int PrvoDijete; int SljedeciBrat; }; struct tree{ Cvor element[1000]; int first; }; tree *InitT(int x,tree *stablo){ delete [] stablo->element; stablo=new tree; stablo->first=0; stablo->element[x].Label=x; stablo->first++; }//InitT int FirstChildT(int x, tree *stablo){ if(x<0) return -1; else{ if(x>=0 && ((x+1)!=0)) return stablo->element[x].PrvoDijete; else return -1; } }//FirstCildT int NextSiblingT(int x, tree *stablo){ if(x<0) return -1; else{ if(stablo->element[x].SljedeciBrat!=-1)return stablo->element[x].SljedeciBrat; else return -1; } }//NextSiblingT int ParentT(int x, tree *stablo){ if(x>0) return x-1; else{ if(x==0) return -1; else cout<<"Cvor ne postoji"<<endl; } }//ParentT int LabelT(int x, tree *stablo){ if(x<0) cout<<"Pogreska"<<endl; else{ return stablo->element[x].Label; } }//LabelT int ChangeLabelT(int x, int y, tree *stablo){ if(x<0) return -1; else stablo->element[y].Label=x; }//changeLabel int RootT(tree *stablo){ return stablo->element[0].Label; }//RootT int CreateT(int x, int y, tree *stablo){ stablo->element[stablo->first].Label=x; stablo->element[stablo->first].PrvoDijete=y; stablo->first++; }//CreateT int DeleteT(int x, tree *stablo){ if(x<0) return -1; else{ if(stablo->element[x].PrvoDijete>0) DeleteT(stablo->element[x].PrvoDijete,stablo); else{ stablo->element[x].Label=-1; stablo->first--; } } }//DeleteT
You need to login to post a comment.
