Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct tree{
- int oznaka;
- tree *left, *right;
- };
- tree *root;
- void Init(int broj){
- root=new tree;
- root->oznaka=broj;
- root->left=0;
- root->right=0;
- }
- tree* LeftChild(tree* cvor){
- if(cvor) return cvor->left;
- return 0;
- }
- tree* RightChild(tree* cvor){
- if(cvor) return cvor->right;
- return 0;
- }
- int Label(tree *cvor){
- return cvor->oznaka;
- }
- void ChangeLabel(int a, tree *cvor){
- cvor->oznaka=a;
- }
- tree* Root(){
- return root;
- }
- tree* Parent(tree* dijete, tree* cvor=root){
- if(!cvor) return 0;
- if(cvor->left==dijete||cvor->right==dijete) return cvor;
- Parent(dijete, cvor->left);
- Parent(dijete, cvor->right);
- }
- void Delete(tree *cvor){
- tree *roditelj=Parent(cvor);
- if(roditelj->left==cvor) roditelj->left=0;
- if(roditelj->right==cvor) roditelj->right=0;
- if(cvor->left) Delete(cvor->left);
- if(cvor->right) Delete(cvor->right);
- delete cvor;
- }
- void CreateLeft(int broj, tree *cvor){
- if(cvor->left) cout<<"Error!"<<endl;
- tree *novi=new tree;
- cvor->left=novi;
- novi->left=0;
- novi->right=0;
- novi->oznaka=broj;
- }
- void CreateRight(int broj, tree *cvor){
- if(cvor->right) cout<<"Error!"<<endl;
- tree *novi=new tree;
- cvor->right=novi;
- novi->left=0;
- novi->right=0;
- novi->oznaka=broj;
- }
Add Comment
Please, Sign In to add comment