Return to Snippet

Revision: 65625
at January 3, 2014 03:02 by tturek


Initial Code
#include<iostream>
using namespace std;

struct node{
    int label;
    node *lijevo,*desno;
    };

node *InitB(int n,node *T){
    T = new node;
    T->lijevo = T->desno = NULL;
    T->label = n;
    return T;
    }

node *RootB(node *T){
    return T;
    }

void ChangeLabelB(int x,node *T){
    T->label = x;
    }

node *ParentB(int n,node *T){
    if(T->label==n) return NULL;
    if(T->lijevo){
        if(T->lijevo->label==n) return T;
        ParentB(n,T->lijevo);
        }
    if(T->desno){
        if(T->desno->label==n) return T;
        ParentB(n,T->desno);
        }
    }

node *LeftChildB(node *T){
    return T->lijevo;
    }

node *RightChildB(node *T){
    return T->desno;
    }

int LabelB(node *T){
    return T->label;
    }

void CreateLeftB(int x,node *T){
    if(T->lijevo) cout << "Zauzeta pozicija!" << endl;
    else{
        node *novi = new node;
        novi->label = x;
        novi->lijevo = NULL;
        novi->desno = NULL;
        T->lijevo = novi;
        }
    }

void CreateRightB(int x,node *T){
    if(T->desno) cout << "Zauzeta pozicija!" << endl;
    else{
        node *novi = new node;
        novi->label = x;
        novi->lijevo = NULL;
        novi->desno = NULL;
        T->desno = novi;
        }
    }

void DeleteB(node *P,node *T){
    node *erase = P,*roditelj = ParentB(P->label,T);
    if(roditelj->lijevo==P) roditelj->lijevo = NULL;
    else roditelj->desno = NULL;
    if(P->lijevo) DeleteB(P->lijevo,T);
    if(P->desno) DeleteB(P->desno,T);
    delete erase;
    }

Initial URL


Initial Description
eto pokazivaca

Initial Title
binarno_pokazivaci

Initial Tags


Initial Language
C++