implementacija pomocu pokazivaca





1
Date Submitted Mon. Jan. 4th, 2010 5:09 PM
Revision 1 of 1
Beginner silly
Tags !important
Comments 2 comments
4 zadatak iz strukutra podataka


struct s_element {
        int vrijednost;
        s_element *left,*right;
};

typedef struct s_element btree;
typedef struct s_element *node;

node ParentB(node n,btree *T){
        if(n==T)exit(0);
        node roditelj;
        if(T->left){
                if(T->left==n)
                        return T->left;
                roditelj=ParentB(n,T->left);
        }
        if(T->right){
                if(T->right==n)
                        return T->right;
                roditelj=ParentB(n,T->right);
        }
        return roditelj;
};

node LeftChildB(node n,btree *T){
        return n->left;
};
node RightChildB(node n,btree *T){
        return n->right;
};
int LabelB(node n,btree *T){
        return n->vrijednost;
};
void ChangeLabelB(int x,node n,btree *T){
        n->vrijednost=x;
};
node RootB(btree *T){
        return T;
};
void CreateLeftB(int x,node n,btree *T){
        if(n->left)exit(0);
        node novi=new s_element;
        n->left=novi;
        novi->right=0;
        novi->left=0;
        novi->vrijednost=x;
};
void CreateRightB(int x,node n,btree *T){
        if(n->right)exit(0);
        node novi=new s_element;
        n->right=novi;
        novi->right=0;
        novi->left=0;
        novi->vrijednost=x;
};
void DeleteB(node n,btree *T){
        static bool vrh=true;
        if(vrh){
                if(ParentB(n,T)->left=n)ParentB(n,T)->left=0;
                if(ParentB(n,T)->right=n)ParentB(n,T)->right=0;
                vrh=false;
        }
        if(n->left)DeleteB(n->left,T);
        if(n->right)DeleteB(n->right,T);
        delete n;
       
};
void InitB(int x,btree *T){
        T->vrijednost=x;
        T->right=0;
        T->left=0;
};
bool ExistsLeftChildB(node n,btree *T){
        if(n->left)
                return true;
        return false;
}
bool ExistsRightChildB(node n,btree *T){
        if(n->right)
                return true;
        return false;
}
 


 

nina mikolaj

Comments

Comments zadatak
Mon. Jan. 4th, 2010 5:27 PM    Beginner silly
Comments implementacija pomoću pok
Mon. Jan. 4th, 2010 5:31 PM    Beginner silly

Voting

Votes Up


Beginner silly

Votes Down