Return to Snippet

Revision: 38695
at January 6, 2011 06:59 by mazorkovi


Initial Code
#ifndef BSTABLO_POLJE_H

#ifndef BSTABLO_POKAZIVAC_H
#define BSTABLO_POKAZIVAC_H

struct element{
    labeltype label;
    struct element *left,*right;
};
typedef struct element *node;
typedef struct element *btree;

btree InitB(labeltype x,btree T){
     T = new element;
     T->label = x;
     T->left = NULL;
     T->right = NULL;
     return T;
}
node RootB(btree T){
     return T;
}
bool ExistsLeftChildB(node n,btree T){
     if(T==NULL) return LAMBDA;
     if(n->left != NULL) return true;
     return false;
}
bool ExistsRightChildB(node n,btree T){
     if(T==NULL) return LAMBDA;
     if(n->right != NULL) return true;
     return false;
}
node LeftChildB(node n,btree T){ 
     return n->left;    
}
node RightChildB(node n,btree T){
     return n->right; 
}
labeltype LabelB(node n,btree T){
     return n->label;
}
int CreateLeftB(labeltype x,node n,btree T){
     element *novi = new element;
     n->left = novi;
     novi->left = NULL;
     novi->right = NULL;
     novi->label = x;
     return 0;
}
int CreateRightB(labeltype x,node n,btree T){
     element *novi = new element;
     n->right = novi;
     novi->left = NULL;
     novi->right = NULL;
     novi->label = x;
     return 0;
}
node ParentB(node n,btree T){
   node cvor = NULL; 
   if(n == T) return 0;
   if(T->left){
      if(T->left == n){
         cvor = T;
         return cvor;
      }
      cvor = ParentB(n,T->left);
   }
   if(!cvor)
   if(T->right){
      if(T->right == n){
         cvor = T;
         return cvor;
      }
      cvor = ParentB(n,T->right);
   }
   return cvor;
}
void DeleteB(node n,btree T){
   if(n->left) DeleteB(n->left,T);
   if(n->right) DeleteB(n->right,T);
   node cvor = ParentB(n,T);
   if(cvor!=0){
      if(cvor->left == n) cvor->left = NULL;
      else cvor->right=NULL;
      delete n;
   }
}
void ChangeLabelB(labeltype x,node n,btree T){
     n->label = x;
}

#endif  /*BSTABLO_POKAZIVAC_H*/

#endif  /*BSTABLO_POLJE_H*/

Initial URL

                                

Initial Description

                                

Initial Title
implementacija bstablo_pokazivac

Initial Tags

                                

Initial Language
C++