/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#ifndef BSTABLO_POLJE_H #ifndef BSTABLO_POKAZIVAC_H #define BSTABLO_POKAZIVAC_H struct element{ labeltype label; struct element *left,*right; }; typedef struct element *node; typedef struct element *btree; btree InitB(labeltype x,btree T){ T = new element; T->label = x; T->left = NULL; T->right = NULL; return T; } node RootB(btree T){ return T; } bool ExistsLeftChildB(node n,btree T){ if(T==NULL) return LAMBD; if(n->left != NULL) return true; return false; } bool ExistsRightChildB(node n,btree T){ if(T==NULL) return LAMBD; if(n->right != NULL) return true; return false; } node LeftChildB(node n,btree T){ return n->left; } node RightChildB(node n,btree T){ return n->right; } labeltype LabelB(node n,btree T){ return n->label; } int CreateLeftB(labeltype x,node n,btree T){ element *novi = new element; n->left = novi; novi->left = NULL; novi->right = NULL; novi->label = x; return 0; } int CreateRightB(labeltype x,node n,btree T){ element *novi = new element; n->right = novi; novi->left = NULL; novi->right = NULL; novi->label = x; return 0; } node ParentB(node n,btree T){ node cvor = NULL; if(n == T) return 0; if(T->left){ if(T->left == n){ cvor = T; return cvor; } cvor = ParentB(n,T->left); } if(!cvor) if(T->right){ if(T->right == n){ cvor = T; return cvor; } cvor = ParentB(n,T->right); } return cvor; } void DeleteB(node n,btree T){ if(n->left) DeleteB(n->left,T); if(n->right) DeleteB(n->right,T); node cvor = ParentB(n,T); if(cvor!=0){ if(cvor->left == n) cvor->left = NULL; else cvor->right=NULL; delete n; } } void ChangeLabelB(labeltype x,node n,btree T){ n->label = x; } #endif /*BSTABLO_POKAZIVAC_H*/ #endif /*BSTABLO_POLJE_H*/