# Posted By

majugurci on 01/14/11

# Statistics

Viewed 399 times
Favorited by 0 user(s)

# binarno stablo polje

/ Published in: C++
`#include <iostream> using namespace std; struct element {       int label;       int used;}; struct bt {       struct element elements [10000];}; typedef struct bt *btree;typedef int node; node ParentB (node n, btree T) {     if (n<2) {              cout << "Greska!" << endl;              return 0;              }     else if (n%2==0) return n/2;     else return n/2-1;} node LeftChildB (node n, btree T) {     if (T->elements[n].used==0) return 0;     else return 2*n;} node RightChildB (node n, btree T) {     if (T->elements[n].used==0) return 0;     else return 2*n+1;} int LabelB (node n, btree T) {    if (T->elements[n].used==0) {                                cout << "Greska!" << endl;                                return 0;                                }    else return T->elements[n].label;} void ChangeLabelB (int x, node n, btree T) {     if (T->elements[n].used==0) {                                cout << "Greska!" << endl;                                return;                                }     else T->elements[n].label=x;} node RooTB (btree T) {       if (T->elements[1].used==0) {                                cout << "Greska!" << endl;                                return 0;                                }         else return 1;} void CreateLeftB (int x, node n, btree T) {     if (T->elements[2*n].used==1 || T->elements[n].used==0) {                             cout << "Greska!" << endl;                             return;                             }          T->elements[2*n].used = 1;          T->elements[2*n].label = x;} void CreateRightB (int x, node n, btree T) {     if (T->elements[2*n+1].used==1 || T->elements[n].used==0) {                             cout << "Greska!" << endl;                             return;                             }          T->elements[2*n+1].used = 1;          T->elements[2*n+1].label = x;} void DeleteB (node n, btree T) {     T->elements[n].used=0;     if (LeftChildB(n, T)) DeleteB(LeftChildB(n, T), T);       if (RightChildB(n, T)) DeleteB(RightChildB(n, T), T);   } btree InitB (int x, btree T) {      T = new bt;      for (int i=0; i<10000; i++)          T->elements[i].used=0;      T->elements[1].label=x;      T->elements[1].used=1;      return T;     }`