@atul anand: the question simply says that in each node the second should
point to the next larger no. which means in your case 7 3 5 1 5 9
the output should be
7->9
5->7
3->5
1->3

On Mon, Mar 26, 2012 at 10:37 AM, Dheeraj Sharma <
dheerajsharma1...@gmail.com> wrote:

> Correct me if am wrong.. i think we can use Stack as follows
> node * minFun(node *head)
> {
>
> stack<node *> st;
> return fun(head,st);
> }
> node * fun(node *ptr,stack<node *> &st)
> {
> if(ptr)
> {
>             node *x=fun(ptr->next,st);
>             while(!st.empty() && (ptr->data)>(st.top()->data))
>                               st.pop();
>
>             if(!st.empty())
>             ptr->high=st.top();
>             st.push(ptr);
> return (x?((ptr->data)<(x->data)?ptr:x):ptr);
> }
> return NULL;
>
> }
> On Sun, Mar 25, 2012 at 12:20 AM, atul anand <atul.87fri...@gmail.com>wrote:
>
>> after push(&s,next) move head also
>> head=head->next;
>>
>>
>> On Sun, Mar 25, 2012 at 12:10 AM, atul anand <atul.87fri...@gmail.com>wrote:
>>
>>> @all : i am getting this right , i guess given a linked list ...you need
>>> to point to next larger element.
>>> so if input linked list is 7 3 5 1 5 9
>>> then nextLarger of each node will point as follows:-
>>>
>>> 3->5
>>> 1->5
>>> 5->9
>>> 7->9
>>> 9->NULL;
>>>
>>> i have no idea why the linked list is modified using merge sort...
>>> anywayzz if the expected output is similar to one i have mentioned above
>>> there this woud work using stack .. complexity O(n) n=number of nodes.
>>>
>>> findLarger(node *head)
>>> {
>>> s1 s;
>>> node *ele,*next;
>>>
>>> s.top=NULL;
>>> push(&s,head);
>>> head=head->next;
>>> while(head!=NULL)
>>> {
>>> next->data=head->data;
>>> if(isEmpty(&s))
>>> {
>>>       ele=pop(&s);
>>>       while(ele->data < next->data)
>>>       {
>>>  ele->nextLarger=next;
>>> if(isEmpty(&s)==0)
>>> {
>>>  break;
>>> }
>>>   ele=pop(&s);
>>>       }
>>>       if(ele->data > next->data)
>>>       {
>>>  push(&s,ele);
>>>       }
>>>
>>> }
>>>
>>> push(&s,next);
>>> }
>>>
>>> On Sat, Mar 24, 2012 at 12:50 AM, Atul Singh <atulsingh7...@gmail.com>wrote:
>>>
>>>> Given a linked list with each node having two pointers : one pointing
>>>> to next node & other to null;
>>>> how will u point the second pointer to next larger no. and return the
>>>> pointer to smallest node
>>>>
>>>>
>>>>
>>>> --
>>>> ATul Singh | Final Year  | Computer Science & Engineering | NIT
>>>> Jalandhar  | 9530739855 |
>>>>
>>>> --
>>>> 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.
>>
>
>
>
> --
> *Dheeraj Sharma*
>
>
>
>  --
> 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