The C language implements non-Cyclic Use of the head and end nodes to process double-stranded tables (the head node and end node)

Source: Internet
Author: User

The C language implements non-Cyclic Use of the head and end nodes to process double-stranded tables (the head node and end node)

I have explained in detail how to delete a node in a double-chain table that does not contain the first and last nodes in my previous blog "delete nodes in non-cyclic double-chain table nodes (do not take the lead node, the processing process is still a little troublesome. Since we learned to use the header and tail nodes to process double-stranded tables, the deletion process is very convenient. Upload the code to https://github.com/chenyufeng1991/deletenodedoublelinkedlist_headlist.

The core code is as follows:

 

// Delete the Node int DeletePosList (Node * pHead, Node * pTail, int pos) {int I = 1; Node * pMove; pMove = pHead-> next; while (pMove! = PTail) {if (I = pos) {pMove-> prior-> next = pMove-> next; pMove-> next-> prior = pMove-> prior; free (pMove); pMove = NULL; printf ("% s FUNCTION execution, node deleted at position pos = % d \ n" ,__ FUNCTION __, pos ); return 1;} I ++; pMove = pMove-> next;} printf ("% s function execution, failed to delete node at position pos = % d \ n ", __function __, pos); return 0;} // delete a Node with the value of x. If the Node exists, delete the int DeleteValueList (Node * pHead, Node * pTail, int x) {Node * pMove; pMove = pHead-> next; while (pMove! = PTail) {if (pMove-> element = x) {pMove-> prior-> next = pMove-> next; pMove-> next-> prior = pMove-> prior; free (pMove); pMove = NULL; printf ("% s function execution, the node with the value of x = % d is successfully deleted \ n ",__ FUNCTION __, x); return 1 ;}pmove = pMove-> next ;} printf ("% s FUNCTION execution, failed to delete node with the value of x" ,__ FUNCTION _); return 0 ;}


 

 

Related Article

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.