+ 2
Can anyone tell me about Linked list?
what is logic for deleting duplicate elements from linked list?
1 Answer
0
Delete Node at a given position in a linked list
head pointer input could be NULL as well for empty list
Node is defined as
class Node {
int data;
Node next;
}
the head and position of the data to be deleted are passes to the function delete.
*/
Node Delete(Node head, int position) {
// Complete this method
Node temp=head;
if(position==0)
{
return temp.next;
}
int count=0;
while(count<position-1)
{
temp=temp.next;
count++;
}
temp.next=temp.next.next;
return head;
}