## Posted By

dare10 on 01/20/14

# Binarno polje

/ Published in: C++

Header datoteka za implementaciju binarnog stabla pomocu polja

`#include<iostream>using namespace std; struct element{    int label;    bool used;};struct tree{    element polje[1000];};tree *InitB(int x,tree *T){    T = new tree;    for(int i=0;i<1000;i++) T->polje[i].used = false;    T->polje[1].label = x;    T->polje[1].used = true;    return T;}int LabelB(int n,tree *T){    return T->polje[n].label;}void ChangeLabelB(int x,int n,tree *T){    T->polje[n].label = x;}int RootB(tree *T){    return T->polje[1].label;}int LeftChildB(int n,tree *T){    if(!T->polje[2*n].used) return -1;    return 2*n;}int RightChildB(int n,tree *T){    if(!T->polje[2*n+1].used) return -1;    return 2*n+1;}int ParentB(int n,tree *T){    if(T->polje[1].label==n) return -1;    if(n%2) return n/2+1;    else return n/2;}void CreateLeftB(int x,int n,tree *T){    if(T->polje[2*n].used) cout << "Zauzeta pozicija!" << endl;    else{    T->polje[2*n].label = x;    T->polje[2*n].used = true;    }}void CreateRightB(int x,int n,tree *T){    if(T->polje[2*n+1].used) cout << "Zauzeta pozicija!" << endl;    else{    T->polje[2*n+1].label = x;    T->polje[2*n+1].used = true;    }}void DeleteB(int n,tree *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;}`