@sagar: The question says Algo should be in place. So use of an array to
print the right border of tree is not advisable. We can do it recursively
without using an array also .

On Sat, Jul 16, 2011 at 10:48 PM, sameer.mut...@gmail.com <
sameer.mut...@gmail.com> wrote:

> @sagar: There is one flaw in the code. Trace ur code 15 and 250 get printed
> twice. otherwise it is fine.
>
>
> On Sat, Jul 16, 2011 at 7:59 PM, sukhmeet singh <sukhmeet2...@gmail.com>wrote:
>
>> please explain the code a bit more.. unable to understand it..an example
>> will be better..
>>
>>
>> On Sun, Jul 17, 2011 at 7:10 AM, Reynald Suz <reynaldsus...@gmail.com>wrote:
>>
>>> Yep!
>>>
>>> On Sun, Jul 17, 2011 at 1:02 AM, swetha rahul 
>>> <swetharahu...@gmail.com>wrote:
>>>
>>>> @Reynald
>>>>                             Will 75 not be included in the tree that u
>>>> have given..??
>>>>
>>>>
>>>> On Sun, Jul 17, 2011 at 12:49 AM, sagar pareek 
>>>> <sagarpar...@gmail.com>wrote:
>>>>
>>>>> here is the code
>>>>> void border(node*);
>>>>> void recur(node*);
>>>>>
>>>>> void border(node *ptr)
>>>>> {
>>>>>  node* tmp; int stack[20],top=0;
>>>>>  if(tmp=ptr->left)
>>>>>  {
>>>>>   while(tmp->left)
>>>>>   {
>>>>>    printf("%d ",tmp->data);
>>>>>    tmp=tmp->left;
>>>>>   }
>>>>>  }
>>>>>  recur(ptr);
>>>>>  if(tmp=ptr->right)
>>>>>  {
>>>>>   while(tmp->right)
>>>>>   {
>>>>>    stack[top++]=tmp->data;
>>>>>    tmp=tmp->right;
>>>>>   }
>>>>>  }
>>>>>  while(top--) printf("%d ",stack[top]);
>>>>>  printf("%d\n",ptr->data);
>>>>> }
>>>>>
>>>>> void recur(node* ptr)
>>>>> {
>>>>>  if(ptr->left) recur(ptr->left);
>>>>>  if(!ptr->left&&!ptr->right) printf("%d ",ptr->data);
>>>>>  if(ptr->right)   recur(ptr->right);
>>>>>
>>>>> }
>>>>>
>>>>> On Sat, Jul 16, 2011 at 7:07 PM, Reynald <reynaldsus...@gmail.com>wrote:
>>>>>
>>>>>> Algo to find the border of a given binary tree. Optimized for space
>>>>>> and time.
>>>>>> Input:
>>>>>>          10
>>>>>>       /         \
>>>>>>     50         50
>>>>>>    /  \         /   \
>>>>>>  25  75   200    20
>>>>>>  / \           /      /    \
>>>>>> 15 35   120    155   250
>>>>>>
>>>>>> Output:50 25 15 35 120 155 250 20 150 10
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> **Regards
>>>>> SAGAR PAREEK
>>>>> COMPUTER SCIENCE AND ENGINEERING
>>>>> NIT 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.
>>>>>
>>>>
>>>>  --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Regards
>>> Reynald Reni
>>> Masters in Software Engineering
>>> CIT - India
>>>
>>>  --
>>> 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.
>>>
>>
>>  --
>> 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.
>>
>
>

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