whats problem with the approch provided by navin http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html
it seems much simpler ...is there any test case for which it wont work ?? On Mon, Jun 4, 2012 at 3:25 PM, Amol Sharma <amolsharm...@gmail.com> wrote: > here is the question ans solution with proper explanation > > http://www.geeksforgeeks.org/archives/11604 > > -- > > > Amol Sharma > Third Year Student > Computer Science and Engineering > MNNIT Allahabad > <http://gplus.to/amolsharma99> > <http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://www.simplyamol.blogspot.com/> > > > > > > > On Sat, Jun 2, 2012 at 1:21 AM, Hassan Monfared <hmonfa...@gmail.com>wrote: > >> 1- read all elements of list into stack >> 2- max = stak.pop() >> 3- if stack.empty() goto 7 >> 4- next=stack.pop() >> 5- if next > max then max=next >> else delete next from list >> 6- repeat from 3 >> 7- end! >> >> Regards, >> >> On Thu, May 31, 2012 at 9:45 PM, atul anand <atul.87fri...@gmail.com>wrote: >> >>> @navin : +1 >>> >>> On 5/31/12, Navin Kumar <algorithm.i...@gmail.com> wrote: >>> > I think the easiest method to do this problem is this: >>> > >>> > >>> http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html >>> > >>> > On Thu, May 31, 2012 at 5:58 PM, Ashish Goel <ashg...@gmail.com> >>> wrote: >>> > >>> >> that is what i have done by using recursion<=>stack. >>> >> >>> >> my code has problem, after free(pCurr);, i should have return pRest; >>> >> >>> >> Best Regards >>> >> Ashish Goel >>> >> "Think positive and find fuel in failure" >>> >> +919985813081 >>> >> +919966006652 >>> >> >>> >> >>> >> On Thu, May 31, 2012 at 4:37 PM, atul anand >>> >> <atul.87fri...@gmail.com>wrote: >>> >> >>> >>> 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. >>> >>> >>> >> >>> >> -- >>> >> 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. >> > > -- > 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.