Implement an algorithm to delete a node in the middle of a one-way linked list. Suppose you can only access this node. Example: input: node c IN a-B-c-d-e of the one-way linked list: No data is returned, but the result of this linked list is a-B-d-epackagetest; publicclassRemoveNode {because only the current node can be accessed, there is no way to get reference from the previous Node
Implement an algorithm to delete a node in the middle of a one-way linked list. Suppose you can only access this node. Example: input: node c IN a-B-c-d-e of the one-way linked list: No data is returned, but the linked list is changed to a-B-d-e package test; public class RemoveNode {// because only the current node can be accessed, there is no way to get reference from the previous Node
Implement an algorithm to delete a node in the middle of a one-way linked list. Suppose you can only access this node.
Example:
Input: node c in one-way linked list a-> B-> c-> d-> e
Result: No data is returned, but the linked list is a-> B-> d-> e.
Package test; public class RemoveNode {// because only the current node can be accessed, there is no way to get the reference of the previous node, so you can only use the method of exchange value, // assign the value of the subsequent Node to the current node, and then delete the deleted node public void removeNode (node Node) {if (node = null) return; if (node. next! = Null) {node. val = node. next. val; node. next = node. next. next;} else {node = null ;}}}