then i guess ...it can be done using stack..with O(n) complexity.. it is similar to finding next greater element ....
http://www.geeksforgeeks.org/archives/8405 element in the stack at the end of the algo...are the element which will remain in the linked list . if stack is not empty then keep poping elements and create a SLL. On Thu, May 31, 2012 at 4:29 PM, Ashish Goel <ashg...@gmail.com> wrote: > yes > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > > On Thu, May 31, 2012 at 2:34 PM, atul anand <atul.87fri...@gmail.com>wrote: > >> @Ashish : please clarify this ques... >> >> delete a node in SLL if it is less than *any* of the succesor node .. >> >> 1 2 8 10 3 4 7 12 >> >> delete 1,2,8,10,3,4,7 >> >> ouput will be single node i.e 12 >> >> dats what question asks? >> >> On Thu, May 31, 2012 at 2:16 PM, Ashish Goel <ashg...@gmail.com> wrote: >> >>> the LL is unsorted, is there any better solution that this? >>> >>> struct node* deleteNodes(struct node *pHead, struct node *pPrev) >>> { >>> struct node *pLL = *pHead; >>> if (!pLL) return NULL; >>> struct node *pCurr = pLL; >>> >>> struct node *pRest = deleteNodes(pCurr->next, pCurr); >>> if (!pRest) return pCurr; >>> if (pCurr->data <pRest->data) >>> { >>> if (pPrev) { pPrev->next = pRest; }; >>> free(pCurr); >>> } >>> else >>> { >>> pCurr->next = pRest; >>> } >>> return pCurr; >>> } >>> >>> >>> Best Regards >>> Ashish Goel >>> "Think positive and find fuel in failure" >>> +919985813081 >>> +919966006652 >>> >>> -- >>> 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. > -- 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.