Return to Snippet

Revision: 68521
at January 19, 2015 08:13 by kgrlic


Initial Code
#include<iostream>
using namespace std;

const int ARRAY_SIZE = 100;
 
struct st_ELEM{
	int label;
	bool used;
};
 
struct st_BTREE{
	st_ELEM node[ARRAY_SIZE];
};
 
st_BTREE *INIT_B(int x, st_BTREE *T){
	T = new st_BTREE;
	for(int i=0;i<ARRAY_SIZE;i++) T->node[i].used = false;
		T->node[1].label = x;
		T->node[1].used = true;
	return T;
}
 
int LABEL_B(int n, st_BTREE *T){
	return T->node[n].label;
}
 
void CHANGE_LABEL_B(int x,int n,st_BTREE *T){
	T->node[n].label = x;
}
 
int ROOT_B(st_BTREE *T){
	return T->node[1].label;
}
 
int LEFT_CHILD_B(int n, st_BTREE *T){
	if(!T->node[2*n].used) return -1;
	return 2*n;
}
 
int RIGHT_CHILD_B(int n,st_BTREE *T){
	if(!T->node[2*n+1].used) return -1;
	return 2*n+1;
}
 
int PARENT_B(int n,st_BTREE *T){
	if(T->node[1].label==n) return -1;
	if(n%2) return n/2+1;
	else return n/2;
}
 
void CREATE_LEFT_B(int x,int n,st_BTREE *T){
	if(T->node[2*n].used) cout << "Polje puno!" << endl;
	else{
		T->node[2*n].label = x;
		T->node[2*n].used = true;
	}
}
 
void CREATE_RIGHT_B(int x,int n,st_BTREE *T){
	if(T->node[2*n+1].used) cout << "Polje puno!" << endl;
	else{
		T->node[2*n+1].label = x;
		T->node[2*n+1].used = true;
	}
}
 
void DELETE_B(int n,st_BTREE *T){
	if(LEFT_CHILD_B(n,T)!=-1) DELETE_B(LEFT_CHILD_B(n,T),T);
	if(RIGHT_CHILD_B(n,T)!=-1) DELETE_B(RIGHT_CHILD_B(n,T),T);
	T->node[n].used = false;
}

Initial URL
test

Initial Description
test

Initial Title
binarno_polje.cpp

Initial Tags


Initial Language
C++