I was given an integer called key as the parameter. I need to know how to delete a node at position key. Ndata is from my Node class.
public void deleteNode(int key)
{
Node<E> temp = head;
while(temp.Ndata != key)//gives me error as not compatible types.
{
temp = temp.next;
}
if(temp == head)
head = temp.next;
else
temp.prev.next = temp.next;
if(temp == tail)
tail == temp.prev;
else
temp.prev.next = temp.next;
}
node.Ndata? Why isn't it anint?keyis supposed to be the node position of the element to delete, or the node value - your question sayskeyis the position, but then your code seems to look for node value (Ndata). To add to the confusion, one of the two answers so far assumes value and the other is assuming position...