Return to Snippet

Revision: 68515
at January 19, 2015 07:36 by akljaic


Initial Code
#include <iostream>
using namespace std;

struct tr{
       int label;
       tr *left, *right;
};

bool ExistLeftChild(tr *n, tr *T){
     if(n->left == NULL) return false;
     return true;
}

bool ExistRightChild(tr *n, tr *T){
     if(n->right == NULL) return false;
     return true;
}

tr *ParentB(tr *n, tr *T){
                tr *cvor;
                bool nadjen = false;
                if(T->left == n || T->right == n){
                           nadjen = true;
                           cvor = T;
                }
                if(nadjen) return cvor;
                if(T->left) ParentB(n,T->left);
                if(T->right) ParentB(n,T->right);                
}

tr *LeftChildB(tr *n, tr *T){
        return n->left;
}

tr *RightChildB(tr *n, tr *T){
        return n->right;
}

int LabelB(tr *n, tr *T){
     return n->label;
}

void ChangeLabelB(int x, tr *n, tr *T){
     n->label = x;
}

tr *RootB(tr *T){
        return T;
}

void CreateLeftB(int x, tr *n, tr *T){
     if(n->left) cout << "Ima vec lijevo dijete!" << endl;
     else {
          n->left = new tr;
          n->left->label = x;
          n->left->left = NULL;
          n->left->right = NULL;
     }
}

void CreateRightB(int x, tr *n, tr *T){
     if(n->right) cout << "Ima vec desno dijete!" << endl;
     else {
          n->right = new tr;
          n->right->label = x;
          n->right->left = NULL;
          n->right->right = NULL;
     }
}

void DeleteB(tr *n, tr *T){
     tr *parent = ParentB(n,T);
     if(parent->left == n) 
                     parent->left = NULL;
     else 
          parent->right = NULL;
     if(n->left) 
                 DeleteB(n->left, T);
     if(n->right) 
                  DeleteB(n->right, T);
     delete n;
}

tr *InitB(int x, tr *T){
        T->left = NULL;
        T->right = NULL;
        T->label = x;
        return T;
}

Initial URL
asdf

Initial Description
asdf

Initial Title
binarno_pokazivac.h

Initial Tags


Initial Language
C++