Return to Snippet

Revision: 68500
at January 19, 2015 05:33 by maxxis95


Initial Code
struct node{
	int label;
	node *Left,*Right;
};
 
node *InitB(int n,node *T){
	T = new node;
	T->Left = T->Right = NULL;
	T->label = n;
	return T;
}
 
node *RootB(node *T){
	return T;
}
 
void ChangeLabelB(int x,node *T){
	T->label = x;
}
 
node *ParentB(int n,node *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);
	}
}
 
node *LeftChildB(node *T){
	return T->Left;
}
 
node *RightChildB(node *T){
	return T->Right;
}
 
int LabelB(node *T){
	return T->label;
}
 
void CreateLeftB(int x, node *T){
	if(T->Left) cout << "Zauzeto" << endl;
	else{
		node *novi = new node;
		novi->label = x;
		novi->Left = NULL;
		novi->Right = NULL;
		T->Left = novi;
	}
}
 
void CreateRightB(int x,node *T){
	if(T->Right) cout << "Zauzeto" << endl;
	else{
		node *novi = new node;
		novi->label = x;
		novi->Left = NULL;
		novi->Right = NULL;
		T->Right = novi;
	}
}
 
void DeleteB(node *P,node *T){
	node *erase = P,*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
pokazivac

Initial Title
Binarno stablo pokazivac

Initial Tags

                                

Initial Language
C++