I have the following code in java but it is not working properly. I need to delete a node from a linked list. Someone help me?
/*
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;
}
*/
// This is a "method-only" submission.
// You only need to complete this method.
Node Delete(Node head, int position) {
// Complete this method
int cont=1;
Node tmp=head;
if(head==null)
{
return null;
}
if(position==0)
{
Node prox= head.next;
head=prox;
return head;
}
Node tmp=head;
Node tmp2=head.next;
while(cont<position)
{
tmp=tmp2;
tmp2=tmp2.next;
cont++;
}
tmp.next=tmp2.next;
return head;
}