For this code to delete an element from a linked list how do I get the head to point to the first element in the list(which is 0)?
public class IntNode1
{
public int item;
public IntNode1 next;
public IntNode1 head;
//////Constructor///////
public IntNode1(int item1, IntNode1 next1)
{
next=next1;
item=item1;
}
public void delete_nth(int n)
{
IntNode1 prev = null;
IntNode1 curr = head;
for(curr=head; curr!=null; prev=curr, curr=curr.next)
{
if(curr.item == n)
{
if(prev==null){
head = curr.next;
}else
{
prev.next=curr.next;
}
}
}
}