Revision: 65699
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 12, 2014 04:13 by mvracan
Initial Code
#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;
}
Initial URL
Initial Description
binarno
Initial Title
binarno stablo pomocu pokazivaca.h
Initial Tags
Initial Language
C++