cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Binary Search Tree

sachinbhatt
8-Gravel

Binary Search Tree

Thus I wrote a binary search tree in C that uses this struct:

 

struct tnode {
    int content;
    struct tnode *left; /* left tree part */
    struct tnode *right; /* right tree part */
};

 

My primary method:

 

int main() {

    struct tnode *Baum = NULL;
    struct tnode *tmpPos = NULL;
    Baum = addelement (Baum, 32);
    Baum = addelement(Baum, 50);
    Baum = addelement(Baum, 60);
    tmpPos = searchnode(Baum,50);
}

 

So, in essence, this generates a Binary search tree with three components (32,50,60). According to this post, my searchnode function is intended to move a reference to the "50" so that I may delete it afterwards. My searchnode Method, on the other hand, only provides the pointer if the element I'm looking for is the root of my binary search tree.

searchnode:

 

struct tnode *searchnode(struct tnode *p, int nodtodelete) {
    if (p == NULL) {
        printf("Baum ist leer oder Element nicht vorhanden \n");
    }

    if ( p -> content == nodtodelete) {
        return p;
    }

    if (p->content > nodtodelete) {
        searchnode (p->right, p->content);
    }
    if (p->content < nodtodelete) {
        searchnode(p->left, p->content);
    }
}

 

 

Perhaps you can assist me.

 

1 REPLY 1

This seems to be a C coding question. Is above code related with any Thingworx functionality? 

Announcements


Top Tags