public DoublyLinkedListNode DeleteANodeInDoublyLinkedList(int data) { DoublyLinkedListNode node = this.head; Console.WriteLine("---Printing DLL after removing the element---"); while (node != null && node.GetDoublyLinkedListNodeData() != data) { node = node.GetDoublyLinkedListNextNode(); } DoublyLinkedListNode nodeToBeDeleted = node; node.GetDoublyLinkedListPreviousNode() .SetDoublyLinkednodeNext(node.GetDoublyLinkedListNextNode()); node.GetDoublyLinkedListNextNode() .SetDoublyLinkedListNodePrevious(node.GetDoublyLinkedListPreviousNode()); return(this.head); }
public void PrintDoublyLinkedList() { if (this.head == null) { Console.WriteLine("Doubly linked list is null! Cannot print anything!"); return; } DoublyLinkedListNode doublyLinkedListNode = this.head; while (doublyLinkedListNode != null) { Console.Write(doublyLinkedListNode.GetDoublyLinkedListNodeData() + " "); doublyLinkedListNode = doublyLinkedListNode.GetDoublyLinkedListNextNode(); } }