@atul: can you explain what this is doing?
for(i=0;i<n;i++)
        {

                 pre=reverse(root->children[i],NULL);

                 if(pre)
                 {
                      pre->children[i]=root;
                 }
         }

when u do tree reversal I see that child points to parent( basically
direction reversed). Now if
    1
                               /    |    \
                             2    3    4
                          /            /    \
                        5           6      7
                     /                        \
                    8                        9

in the last iteration along leftmost path , pointer to 8 is returned(pre)
whose child is then assigned as 5 using pre->children[0]=root
if 5 had another child say 'x' then after x is returned from thr recursive
call, u wud assign pre->children[1]=root where root is pointer to 5
here..but 8 and x have only one child which is 5  and indexes used for each
are 0 and 1 instead of just 0..am i understanding it wrongly?


On Wed, Dec 21, 2011 at 8:37 PM, atul anand <[email protected]> wrote:

> adding one more check :- this one is updated
>
>
> node *Reverse(node *root,node *pre)
> {
>      flag=0;
>
>         for i=0 to n
>            if (root->children[i]!=NULL)
>            {
>                  flag=1;
>                  break;
>            }
>         end for
>
>         if( ! flag)
>         {
>               add root to the list;
>               return root;
>         }
>
>         for(i=0;i<n;i++)
>         {
>             if(root->children[i]!=NULL)
>              {
>                             pre=reverse(root->children[i],NULL);
>
>                               if(pre)
>                               {
>                                   pre->children[i]=root;
>                               }
>               }
>         }
>
> return root;
>
> }
>
>
> On Thu, Dec 22, 2011 at 9:35 AM, atul anand <[email protected]>wrote:
>
>> adding break to first loop...just to avoid unnecessary iterations.
>> if (root->children[i]!=NULL)
>>            {
>>                  flag=1;
>>                  break;
>>
>>            }
>>         end for
>>
>>
>> On Wed, Dec 21, 2011 at 10:59 PM, atul anand <[email protected]>wrote:
>>
>>> @shashank:
>>>
>>> yeah here is the algo , please me know if you find any bug:-
>>>
>>>
>>> node *Reverse(node *root,node *pre)
>>> {
>>>      flag=0;
>>>
>>>         for i=0 to n
>>>            if (root->children[i]!=NULL)
>>>            {
>>>                  flag=1;
>>>            }
>>>         end for
>>>
>>>         if( ! flag)
>>>         {
>>>               add root to the list;
>>>               return root;
>>>         }
>>>
>>>         for(i=0;i<n;i++)
>>>         {
>>>
>>>                  pre=reverse(root->children[i],NULL);
>>>
>>>                  if(pre)
>>>                  {
>>>                       pre->children[i]=root;
>>>                  }
>>>          }
>>>
>>> return root;
>>>
>>> }
>>>
>>>
>>>
>>>
>>> On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank <[email protected]
>>> > wrote:
>>>
>>>> @atul,, yeah , but can you write some proper psuedo code/ Algorithm
>>>> then we can discus more about test cases.
>>>>
>>>> Thanks
>>>> Shashank
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ.
>>>>
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
 "People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily."

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

Reply via email to