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.