Return to Snippet

Revision: 68459
at January 19, 2015 02:35 by mateocindric


Initial Code
#include<iostream>
using namespace std;

int bstablo[1000];

void InitB(int n, int bstablo[]){
bstablo[1]=n;
for(int i=2;i<1000;i++)
    bstablo[i]=-1;        
}

int LabelB(int n, int bstablo[]){
    return bstablo[n];    
}

void ChangeLabelB(int x,int n, int bstablo[]){
bstablo[n]=x;         
}

int RootB(int bstablo[]){
return 1;    
}

int ParentB(int n, int bstablo[]){
if(n==RootB(bstablo)) 
      return -1;    
if(n%2)
       return (n-1)/2;
else 
       return n/2;
}

int LeftChildB(int n,int bstablo[]){
if(LabelB(n*2,bstablo)==-1)
    return -1;
else 
     return n*2; 
}

int RightChildB(int n, int bstablo[]){
if(LabelB(n*2+1,bstablo)==-1)
    return -1;
else 
    return n*2+1;
}

bool CreateRightB(int x, int n, int bstablo[]){
if(RightChildB(n, bstablo)!=-1)
    return false;
bstablo[n*2+1]=x;
return true;       
}

bool CreateLeftB(int x, int n, int bstablo[]){
if(LeftChildB(n, bstablo)!=-1)
    return false;
bstablo[n*2]=x;
return true;     
}

void DeleteB(int n, int bstablo[]){
if(LeftChildB(n, bstablo)!=-1)
        DeleteB(LeftChildB(n, bstablo),bstablo);
if(RightChildB(n, bstablo)!=-1)
        DeleteB(RightChildB(n, bstablo),bstablo);
bstablo[n]=-1; 
}

Initial URL

                                

Initial Description
bstablo_polje.h

Initial Title
bstablo_polje.h

Initial Tags

                                

Initial Language
C++