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 <atul.87fri...@gmail.com> 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 <atul.87fri...@gmail.com>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 
>> <shashank7andr...@gmail.com>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 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.
>>>
>>
>>
>

-- 
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