Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Supposed the linked list 1 -> 2 -> 3 -> 4
is and you were given the third node with value 3
, the linked list should become 1 -> 2 -> 4
a Fter calling your function.
Issue: Remove the node from the list only by giving the order to one of the nodes in the list.
Delete an element of the list, only knowing that it will be deleted from the same value based on the head node, and the value of the deletion point. For a given node to be removed from the list, there is no idea. Read the explanation on the net, originally this is the basic operation of the list, O (1) time can be completed. See I'm not familiar with the list.
1 void deletenode (listnode* node) {2 3 node->val = node->next-> Val; 4 Node->next = node->next->Next; 5 6 }
The topic mentions a given node and will not be the end node. This way the algorithm is flawed because the last element cannot be deleted. Not really, just to insert a symbol at the end of the original list to represent NULL, then the algorithm is the complete operation of the entire list.
[Leetcode] 237. Delete Node in a Linked List problem solving idea