/ Published in: C++
Datoteka zaglavlja za zadatak 4
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
struct telement{ int label, root; telement *left, *right; }; typedef struct telement *tnode; typedef struct telement *ttree; tnode ParentB (tnode node, ttree tree){ tnode par; if (LeftChildB(node, tree)){ if (tree->left == node) return tree->left; par = ParentB (node, tree->left); } if (RightChildB(node, tree)){ if (tree->right == node) return tree->right; par = ParentB(node, tree->right); } return par; }; tnode LeftChildB (tnode node, ttree tree){ if (node->left != NULL) return node->left; if (node->left == NULL) cout<<"Ne postoji lijevo dijete!"<<endl; }; tnode RightChildB (tnode node, ttree tree){ if (node->right != NULL) return node->right; if (node->right == NULL) cout<<"Ne postoji desno dijete!"<<endl; }; int LabelB (tnode node, ttree tree){ if(RootB (tree)){ return node->label; } else cout<<"ERROR"<<endl; }; void ChangeLabelB (int label, tnode node, ttree tree){ if (!RootB (tree)) cout << "Ne postoji cvor!" << endl; else tree->label = label; }; tnode RootB (ttree tree){ if (tree) return tree; else cout<<"ERROR"<<endl; }; void CreateLeftB (int label, tnode node, ttree tree){ tnode novi = new telement; if (LeftChildB(node, tree)){ cout<<"Vec postoji lijevo dijete!"<<endl; return; } else{ novi->label = label; novi->left = NULL; novi->right = NULL; node->left = novi; } }; void CreateRightB (int label, tnode node, ttree tree){ tnode novi = new telement; if (RightChildB(node, tree)){ cout<<"Vec postoji desno dijete!"<<endl; return; } else{ novi->label = label; novi->left = NULL; novi->right = NULL; node->right = novi; } }; void DeleteB (tnode node, ttree tree){ if (LeftChildB (node, tree)) DeleteB (node->left, tree); if (RightChildB (node, tree) ) DeleteB (node->right, tree); delete node; }; void InitB (int root, ttree tree){ tnode novi = new telement; novi->root = root; novi->left = NULL; novi->right = NULL; tree = novi; };