understandind tree insertion operation

Discussion in 'General Computer Support' started by veronica, Sep 20, 2012.

  1. veronica

    veronica

    Joined:
    Sep 20, 2012
    Messages:
    1
    Likes Received:
    0
    BST Insert( int X, BST T )
    {

    if(T==NULL)
    {
    BST node=(BST)malloc(sizeof(struct TreeNode));
    node->Element=X;
    node->Left=NULL;
    node->Right=NULL;
    T=node;
    }
    else if(X<T->Element)
    T->Left=Insert(X,T->Left);
    else
    T->Right=Insert(X,T->Right);
    return T;
    }


    //here i could not understand why are we assigning T->Left=Insert(X,T->Left);
    we could have done T=Insert(X,T->Left);----------(gives wrong result though)
    because ultimately when a function call is made the new value is going to T only
     
    veronica, Sep 20, 2012
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.