@karthik here u'r just making the pointer null that means pointer reference gets lost but
? 1->2>3 here ? means pointer that gets lost if u make it null but the 2 node is still pointing to 3 , how would u solve dis one. On Mon, Sep 5, 2011 at 7:13 PM, kARTHIK R <k4rth...@gmail.com> wrote: > Just add the necessary checks for the end conditions. > > void delete(node *ptr) { > > node *newptr = ptr->next; > if(newptr) { > ptr->val = newptr->val; > ptr->next = newptr->next; > delete newptr; > } > else ptr=NULL; > > } > > > Karthik R, > R&D Engineer, > Tejas Networks. > > > > On Mon, Sep 5, 2011 at 7:00 PM, $hr! k@nth <srithb...@gmail.com> wrote: > >> @sukran: So can't I delete the last node, if pointer to that node is >> given? Can you please elaborate it.. >> >> >> On Mon, Sep 5, 2011 at 6:47 PM, sukran dhawan <sukrandha...@gmail.com>wrote: >> >>> it wont work.u can set a sentinel value for the last node and make it >>> dummy.so every time u scan the list u need to compare >>> >>> while(list != null and list->vlue != dummy) >>> >>> >>> On Mon, Sep 5, 2011 at 6:34 PM, $hr! k@nth <srithb...@gmail.com> wrote: >>> >>>> How this will work if the node to be deleted is the last node?? >>>> >>>> >>>> On Mon, Sep 5, 2011 at 5:32 PM, kARTHIK R <k4rth...@gmail.com> wrote: >>>> >>>>> void delete(node *ptr) { >>>>> >>>>> node *newptr = ptr->next; >>>>> ptr->val = newptr->val; >>>>> ptr->next = newptr->next; >>>>> delete newptr; >>>>> >>>>> } >>>>> >>>>> >>>>> Karthik R, >>>>> R&D Engineer, >>>>> Tejas Networks. >>>>> >>>>> >>>>> >>>>> On Mon, Sep 5, 2011 at 5:29 PM, $hr! k@nth <srithb...@gmail.com>wrote: >>>>> >>>>>> Hi guyz, >>>>>> >>>>>> *Given only a pointer to a node to be deleted in a singly linked >>>>>> list, how do you delete it?* >>>>>> >>>>>> if that node is in between the list, we can copy the data from next >>>>>> node into this node and we can delete the next node. >>>>>> what if the node to be deleted is last node ?? >>>>>> if the list is circular linked list, does it make any difference?? >>>>>> >>>>>> -- >>>>>> Regards, >>>>>> $hr!k@nth >>>>>> >>>>>> -- >>>>>> 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, >>>> $hr!k@nth >>>> >>>> -- >>>> 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, >> $hr!k@nth >> >> -- >> 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.