## Posted By

hcosic2 on 01/18/15

# binstablo_polje.h

/ Published in: C++

Implementacija binarnog stabla pomoÄ‡u polja

`#include <iostream>#define max 1000 int binT[10000]; int RootB (int binT[]) {     return 1;} int LabelB (int n, int binT[]) {     return binT[n];} int ParentB (int n, int binT[]) {     if (n==RootB(binT))return -1;     if (n%2)return (n-1)/2;     else return n/2;} int LeftChildB (int n, int binT[]) {     if (LabelB(n*2, binT)==-1) return -1;     return n*2;} int RightChildB (int n, int binT[]) {     if (LabelB(n*2+1, binT)==-1)return -1;     return n*2+1;} void ChangeLabelB (int x, int n, int binT[]) {      binT[n] = x;} bool CreateLeftB (int x, int n, int binT[]) {     if (LeftChildB(n, binT)!=-1)return false;     binT[n*2] = x;     return true;} bool CreateRightB (int x, int n, int binT[]) {     if (RightChildB(n, binT)!=-1)return false;     binT[n*2+1] = x;     return true;} void DeleteB (int n, int binT[]) {      if (LeftChildB(n, binT)!=-1)        DeleteB(LeftChildB(n, binT), binT);      if (RightChildB(n, binT)!=-1)        DeleteB(RightChildB(n, binT), binT);      binT[n]=-1;} void InitB (int n, int binT[]) {      for (int i=0; i<1000; i++)        binT[i] = -1;      binT[1] = n;}`