Delete without head pointer
You are given a pointer/reference to a node to be deleted in a linked list.The task is to delete the node. Pointer/reference to head node is not given.
You may assume that the node to be deleted is not the last node.
Algorithm:
- Iterate list from given node till node.next != null
- During each iteration node.data = node.next.data
- Set previousNode = node
- Set node = node.get
- Set previousNode.next = null
Latest Source Code:
Github: ListDeleteNodeWithoutHead.java
Output:
1 2 3 4 5 1 2 4 5 1 2 5