understandind tree insertion operation

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

  1. veronica

    veronica

    Joined:
    Sep 20, 2012
    Messages:
    1
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amy L.
    Replies:
    0
    Views:
    2,432
    Amy L.
    Jul 24, 2003
  2. Fischer Karsten

    Online Insertion and Removal 7206VXR

    Fischer Karsten, Nov 30, 2004, in forum: Cisco
    Replies:
    6
    Views:
    1,517
    Karsten Fischer
    Dec 3, 2004
  3. AM
    Replies:
    2
    Views:
    2,466
    Walter Roberson
    Jan 8, 2005
  4. AM
    Replies:
    0
    Views:
    413
  5. Jeff Wisnia

    Help With Old EZ-TREE Family Tree Program

    Jeff Wisnia, Jul 23, 2007, in forum: Computer Support
    Replies:
    7
    Views:
    1,266
Loading...

Share This Page