## Posted By

javert on 01/19/15

# btree_array.h

/ Published in: C++

Implementacija ATP stablo, polje

`struct element {	int v;	bool u;}; struct tree {	element values[10000];}; typedef tree* binTree;typedef int node; binTree initB(int x, binTree T) {	T = new tree; 	T->values[0].u=0;	for(int i=2; i<10000; i++) {		T->values[i].u=0;		T->values[i].v=0;	} 	T->values[1].v = x;	T->values[1].u = 1; 	return T;} node rootB(binTree T) {	return 1;} node parentB(node n, binTree T) {	if(n==rootB(T))		return 0;	else return n/2;} node leftChildB(node n, binTree T) {	if(T->values[n*2].u==0)		return 0;	else return n*2;} node rightChildB(node n, binTree T) {	if(T->values[n*2+1].u==0)		return 0;	else return n*2+1;} int labelB(node n, binTree T) {	int label=T->values[n].v;	return label;} void changeLabelB(int x, node n, binTree T) {	if(n>=0 && n<10000)		T->values[n].v = x;} void createLeftB(int x, node n, binTree T) {	if(n<0 || n>10000) return; 	if(T->values[n*2].u)		return; 	T->values[n*2].v = x;	T->values[n*2].u = 1;} void createRightB(int x, node n, binTree T) {	if(n<0 || n>10000) return; 	if(T->values[n*2+1].u)		return; 	T->values[n*2+1].v = x;	T->values[n*2+1].u = 1;} bool existsLeftChildB(node n, binTree T) {	node temp = leftChildB(n,T);	if(T->values[temp].u) return true;	else return false;} bool existsRightChildB(node n, binTree T) {	node temp = rightChildB(n,T);	if(T->values[temp].u) return true;	else return false;} void deleteB(node n, binTree T) {	if(n==1)return;	if(n>=10000)return; 	if(T->values[n*2].u)		deleteB(n*2, T);	if(T->values[n*2+1].u)		deleteB(n*2+1, T); 	T->values[n].u = 0;}`