Help?? Please How to remove kthElementFromLinkList
How to remove kthElementFromLinkList
take two pointers, one is prev and other is next. at ith iteration, prev will point to (i-1)th element while next will point to ith element. after k steps, prev will point to k-1th element.
then do:
prev->next = next->next
and free(next)
thanks.
Hi Gaurav free(next) work in java ???
And is it like taking list as double linkedlist ??
No. free(next) doesn’t work in java. you dont need to write it as unused java objects are collected automatically by garbage collector.
instead of free(next) , just do next.next = null(and instead of ->operator , use . in java)
…
and No, its not like taking list as double linked list. Doubly linked list is entirely different concept.
you need to take two pointers so that you should have a pointer pointing to an element just before the element you want to delete.
thanks.