Civet cat for Prince-delete nodes in headless single-linked list
@ (Algorithmic Learning)
Learn from the beauty of programming.
A very interesting way of doing it.
Given a single-linked list without a head pointer, one pointer points to an intermediate node in the secondary single-linked list, deleting the node.
Analysis: How to work around the removal of a precursor that is impossible to find. Since each node is only the content of the same, but the same form, whether you can consider rushes, civet cats for the Prince.
The current node content is replaced with the contents of the back node, and the subsequent nodes are removed from memory, so that the linked list is still connected and the content is exactly the result of deleting the current node. Don't look at the knot, who can see what we've done.
Core code:
Pcurrent->next = pnext->next; The current node pointer is pointed to the successor
Pcurrent->data = pnext->data;//The current node content is replaced by the successor node
delete pnext;
Three lines of code, a row to deprive the subsequent nodes of the relationship, a row to remove the value of the successor node, the last line to delete the successor node, there is no value.
Cruel.