Return to Snippet

Revision: 68499
at January 19, 2015 05:32 by maxxis95


Initial Code
struct ele{
	int label;
	bool used;
};
 
struct btree{
	ele elem[1000];
};
 
btree *InitB(int x,btree *T){
	T = new btree;
	for(int i=0;i<1000;i++) T->elem[i].used = false;
	T->elem[1].label = x;
	T->elem[1].used = true;
	return T;
}
 
int LabelB(int n,btree *T){
	return T->elem[n].label;
}
 
void ChangeLabelB(int x,int n,btree *T){
	T->elem[n].label = x;
}
 
int RootB(btree *T){
	return T->elem[1].label;
}
 
int LeftChildB(int n,btree *T){
	if(!T->elem[2*n].used) return -1;
	return 2*n;
}
 
int RightChildB(int n,btree *T){
	if(!T->elem[2*n+1].used) return -1;
	return 2*n+1;
}
 
int ParentB(int n,btree *T){
	if(T->elem[1].label==n) return -1;
	if(n%2) return n/2+1;
	else return n/2;
}
 
void CreateLeftB(int x,int n,btree *T){
	if(T->elem[2*n].used) cout << "Zauzeto!" << endl;
	else{
		T->elem[2*n].label = x;
		T->elem[2*n].used = true;
	}
}
 
void CreateRightB(int x,int n,btree *T){
	if(T->elem[2*n+1].used) cout << "Zauzeto!" << endl;
	else{
		T->elem[2*n+1].label = x;
		T->elem[2*n+1].used = true;
	}
}
 
void DeleteB(int n,btree *T){
	if(LeftChildB(n,T)!=-1) DeleteB(LeftChildB(n,T),T);
	if(RightChildB(n,T)!=-1) DeleteB(RightChildB(n,T),T);
	T->elem[n].used = false;
}

Initial URL

                                

Initial Description
polje

Initial Title
Binarno stablo polje

Initial Tags

                                

Initial Language
C++