I'm kind of at this stage trying to invoke my DeleteNode method correctly:
public void DeleteNode()
{
//Check for ERROR if you are deleting a node which is referred by many pointers.
//Update all these pointers before deleting (releasing) memory!
if (next == null)//last node
{
//Delete the last node
//Look lecture slides for the pseudocode for deleting last node next.next = null; } else if (prev == null) { //Delete head node //Look lecture slides for the pseudocode for deleting head node MyDoublyLinkedList temp = prev.head; head = prev.head.next; temp = null; } else { //Update the next node pointer and reset the deleted node to null //Look lecture slides for the pseudocode for deleting a node in the middle
//Add your code here
MyDoublyLinkedList temp = next.next;
next.next = temp.next;
temp.next = null;
}
}
With this? P.S. Peter is the fourth element of the list that I have to delete
//Delete Peter node and then traverse forward
//Add your code here
for (int k = 0; k < 4; k++)
{
node.DeleteNode();
node.TraverseForward(node);
Console.WriteLine(" ");
}