Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > understandind tree insertion operation

Reply
Thread Tools

understandind tree insertion operation

 
 
veronica veronica is offline
Junior Member
Join Date: Sep 2012
Posts: 1
 
      09-20-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic question in binary tree node insertion Indrajeet C Programming 2 10-11-2009 07:16 PM
Boolean operation and arithmetic operation Buzz Lightyear C++ 10 08-12-2009 01:27 PM
I/O operation, file operation behaviou raan C++ 2 08-16-2007 07:13 PM
Does bit operation always work more efficiently than math operation? david ullua C Programming 13 03-01-2006 11:02 PM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM



Advertisments