Return to Snippet

Revision: 68505
at January 19, 2015 06:11 by Mata4004


Initial Code
#include <iostream>
using namespace std;
 
struct element {
    int label;
    element *left, *right;
};
 
element *bstablo = new element;
 
element *Rootb (element *bstablo) {
    return bstablo;
}
 
int Labelb (element *el) {
    return el->label;
}
 
element *Parentb (element *search, element *bstablo) {
    element *pomocni1=NULL, *pomocni2=NULL;
    if (bstablo->left == search || bstablo->right == search)
        return bstablo;
    if (bstablo->left != NULL)
        pomocni1 = Parentb(search,bstablo->left);
    if (bstablo->right != NULL)
        pomocni2 = Parentb(search, bstablo->right);
    if (pomocni1 != NULL)
        return pomocni1;
    if (pomocni2 != NULL)
        return pomocni2;
    return NULL;
    }
 
element *LeftChildb (element *el) {
        return el->left;
}
 
element *RightChildb (element *el) {
    return el->right;
}
 
void ChangeLabelb (int value, element *el) {
    el->label = value;
}
 
bool CreateLeftb (int value, element *el) {
    if (LeftChildb(el) != NULL)
        return false;
    element *novi = new element;
    el->left = novi;
    novi->label = value;
    novi->left = NULL;
    novi->right = NULL;
    return true;
}
 
bool CreateRightb (int value, element *el) {
    if (RightChildb(el) != NULL)
        return false;
    element *novi = new element;
    el->right = novi;
    novi->label = value;
    novi->left = NULL;
    novi->right = NULL;
    return true;
}
 
void Deleteb (element *el, element *stablo) {
    if (el->left != NULL)
        Deleteb(el->left, bstablo);
    if (el->right != NULL)
        Deleteb(el->right,bstablo);
    if (el != Rootb(stablo) && LeftChildb(Parentb(el, bstablo))==el)
        Parentb(el, bstablo)->left = NULL;
    else if (el != Rootb(bstablo))
        Parentb(el, bstablo)->right = NULL;
    delete el;
}
 
void Initb (int value, element *bstablo) {
    bstablo->right = NULL;
    bstablo->left = NULL;
    bstablo->label = value;
}
 
element *Search (element *el, int value) {
    if (el->label == value)
       return el;
    if (el->left != NULL)
       if (Search(el->left, value) != NULL)
          return Search(el->left, value);
    if (el->right != NULL)
       if (Search(el->right, value) != NULL)
          return Search(el->right, value);
    return NULL;
}

Initial URL
http://snipplr.com/view/87767/stablopokazivach/

Initial Description
Pokazivac

Initial Title
stablo_pokazivac.h

Initial Tags


Initial Language
C++