Posted By

mvracan on 01/12/14

Statistics

Viewed 425 times
Favorited by 0 user(s)

binarno stablo pomocu pokazivaca.h

/ Published in: C++
`#include<iostream>using namespace std; struct pnode{    int label;    pnode *left,*right;    }; pnode *InitB(int n,pnode *T){    T = new pnode;    T->left = T->right = NULL;    T->label = n;    return T;    } pnode *RootB(pnode *T){    return T;    } void ChangeLabelB(int x,pnode *T){    T->label = x;    } pnode *ParentB(int n,pnode *T){    if(T->label==n) return NULL;    if(T->left){        if(T->left->label==n) return T;        ParentB(n,T->left);        }    if(T->right){        if(T->right->label==n) return T;        ParentB(n,T->right);        }    } pnode *LeftChildB(pnode *T){    return T->left;    } pnode *RightChildB(pnode *T){    return T->right;    } int LabelB(pnode *T){    return T->label;    } void CreateLeftB(int x,pnode *T){    if(T->left) cout << "Lijevo dijete veÄ‡ postoji!" << endl;    else{        pnode *novi = new pnode;        novi->label = x;        novi->left = NULL;        novi->right = NULL;        T->left = novi;        }    } void CreateRightB(int x,pnode *T){    if(T->right) cout << "Desno dijete veÄ‡ postoji!" << endl;    else{        pnode *novi = new pnode;        novi->label = x;        novi->left = NULL;        novi->right = NULL;        T->right = novi;        }    } void DeleteB(pnode *P,pnode *T){    pnode *erase = P;    if(P!=T){             pnode *roditelj = ParentB(P->label,T);             if(roditelj->left==P) roditelj->left = NULL;             else roditelj->right = NULL;             }    if(P->left) DeleteB(P->left,T);    if(P->right) DeleteB(P->right,T);    delete erase;    }`