Revision: 38621
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 6, 2011 01:42 by sesveteboy
Initial Code
struct element {
int label;
element *left,*right;
};
typedef element *node;
typedef element bt;
node ParentB(node n, bt* T) {
if (n == T) return NULL;
node roditelj = NULL;
if (T->left) {
if (T->left == n) return T;
else roditelj = ParentB(n, T->left);
}
if(T->right) {
if (T->right == n) return T;
else roditelj = ParentB(n, T->right);
}
return roditelj;
}
node LeftChildB(node n, bt* T) {
if(!n || !n->left) return NULL;
return n->left;
}
node RightChildB(node n, bt* T) {
if(!n || !n->right) return NULL;
return n->right;
}
int LabelB(node n, bt* T) {
return n->label;
}
void ChangeLabelB(int x, node n, bt* T) {
if(!n) return;
n->label = x;
}
node RootB(bt* T) {
if(!T) return NULL;
return T;
}
void CreateLeftB(int x, node n, bt* T) {
if(n->left) {
cout << "Greska" << endl << endl;
return;
}
node novi = new element;
n->left = novi;
novi->label = x;
novi->left = NULL;
novi->right = NULL;
}
void CreateRightB(int x, node n, bt* T) {
if(n->right) {
cout << "Greska" << endl << endl;
return;
}
node novi = new element;
n->right = novi;
novi->label = x;
novi->left = NULL;
novi->right = NULL;
}
void DeleteB(node n, bt* T) {
static bool jednom = false;
if(!jednom) {
node roditelj = ParentB(n, T);
if(roditelj->left == n) roditelj->left = NULL;
else roditelj->right = NULL;
jednom = true;
}
if(n->left) DeleteB(n->left, T);
if(n->right) DeleteB(n->right, T);
delete n;
}
bt* InitB(int x, bt* T) {
T = new element;
T->label = x;
T->left = NULL;
T->right = NULL;
return T;
}
Initial URL
Initial Description
Initial Title
Implementacija binarnog stabla pomocu pokazivaca
Initial Tags
podataka
Initial Language
C++