Civet cat for Prince--Delete the node in the headless single-linked list

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.