@ sanchit
m dong inorder traversal and at every step chking whether the node's p
pointer is pointing to its inorder predecesor, which is temp or not and
making it NULL otherwise. when count is 0 the node do not hv any predecessor
so m directly pointing that to NULL.

*please see the below alg0 , the abv algo by me is incomplete (sorry  :(
     ) *

int count=0;  //global
void modified_inorder(node *root){
       if(root!=NULL){
             modified_inorder(root->left);
             node *temp;
             if(count==0){
                  root->p=NULL;
                  temp=root;
                  count++;
              }
             else{
                if(root->p!=temp){
                    root->p=NULL;
                }
                temp=root;
             modified_inorder(root->right);
          }
    }
}

On Mon, Feb 14, 2011 at 9:45 PM, sanchit mittal <sm14it...@gmail.com> wrote:

> explain algo instead of writing the code.....
> thanx
>
>
> On Mon, Feb 14, 2011 at 9:28 PM, jalaj jaiswal 
> <jalaj.jaiswa...@gmail.com>wrote:
>
>> @tushar that would modify the tree structure
>>
>> here is a different approach
>>
>> int count=0;  //global
>> void modified_inorder(node *root){
>>        if(root!=NULL){
>>              modified_inorder(root->left);
>>              node *temp;
>>              if(count==0){
>>                   root->p=NULL;
>>                   temp=root;
>>                   count++;
>>               }
>>              else{
>>                 if(root->p!=temp){
>>                     root->p=NULL;
>>                 }
>>                 temp=root;
>>
>>             }
>>
>> }
>>
>> On Mon, Feb 14, 2011 at 7:59 PM, Tushar Bindal <tushicom...@gmail.com>wrote:
>>
>>> I think the following algo should work:
>>> 1. Create a DLL of the inorder traversal of the tree
>>> 2. for each node, check whether P of that node points to the previous
>>> node in the DLL or not.
>>> 3. If not, assign it value NULL
>>>
>>>
>>>
>>> --
>>> Tushar Bindal
>>> Computer Engineering
>>> Delhi College of Engineering
>>> Mob: +919818442705
>>> E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> With Regards,
>> *Jalaj Jaiswal* (+919019947895)
>> Software developer, Cisco Systems
>> B.Tech IIIT ALLAHABAD
>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Sanchit Mittal
> Second Year Undergraduate
> Computer Engineering
> Delhi College of Engineering
> ph- +919582414494
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
With Regards,
*Jalaj Jaiswal* (+919019947895)
Software developer, Cisco Systems
B.Tech IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to