Return to Snippet

Revision: 68490
at January 19, 2015 05:28 by mateom11


Initial Code
#include <iostream>
 
using namespace std;
 
struct element {
	int label;
	bool used;
};
 
struct bt {
	struct element polje[1000];
};
 
typedef struct bt* btree;
typedef int node;
 
 
 
void InitB(int x,btree T){
	for(int i=0;i<1000;i++) T->polje[i].used=false;
	T->polje[1].label = x;
	T->polje[1].used=true;
}
 
int LabelB(node n,btree T){
	return T->polje[n].label;
}
 
void ChangeLabelB(int x,node n,btree T){
	T->polje[n].label=x;
}
node RootB(btree T){
 
	if (T->polje[1].used) return 1;
	else return -1;
}
 
node ParentB(node n,btree T){
	if(n==1) return -1;	
	return n/2;
}                                                               
 
void CreateLeftB(node x,node n,btree T){
	if (!T->polje[n*2].used && T->polje[n].used){
 		T->polje[n*2].used=true;
		T->polje[n*2].label=x; 	
	 }	
 	else cout<<"Greska, cvor se nemoze kreirati!"<<endl;
}
 
void CreateRightB(int x,node n,btree T){
 if (!T->polje[n*2+1].used && T->polje[n].used){
 	T->polje[n*2+1].used=true;
	T->polje[n*2+1].label=x; 	
 }	
 else cout<<"Greska, cvor se nemoze kreirati!"<<endl;
}
 
node LeftChildB(node n,btree T){
	if(T->polje[n*2].used) return n*2;
	else return -1;
}
node RightChildB(node n,btree T){
	if(T->polje[n*2+1].used) return n*2+1;
	else return -1;
}
 
void DeleteB(node n,btree T){
	if(LeftChildB(n,T)!=-1) DeleteB(LeftChildB(n,T),T);
    if(RightChildB(n,T)!=-1) DeleteB(RightChildB(n,T),T);
    T->polje[n].used = false;
}
 
bool ExistRightChild(node n,btree T){
	if(T->polje[2*n+1].used) return true;
	return false;
}
 
bool ExistLeftChild(node n,btree T){
	if(T->polje[2*n].used) return true;
	return false;
}

Initial URL


Initial Description
Binarno_stablo_polje

Initial Title
Binarno_stablo_polje.h

Initial Tags


Initial Language
C++