C language implementation of non-cyclic doubly linked List node deletion (lead node tail junction)

Source: Internet
Author: User

I was in a previous blog "C language implementation of the non-circular doubly linked list node deletion (do not take the lead node)" in detail on the non-head and tail nodes of the double linked list to delete a node, the process is still a little more trouble. The removal process has been very handy since we learned to use the tail node to process the doubly linked list. The code is uploaded to Https://github.com/chenyufeng1991/DeleteNodeDoubleLinkedList_HeadList.

The core code is as follows:

Delete the POS location 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, delete pos=%d location node succeeded \ n", __function__,pos);        return 1;        } i++;    Pmove = pmove->next;    } printf ("%s function execution, deletion of node pos=%d location failed \ n", __function__,pos); return 0;}    Delete the node with the value x, and if present, 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, delete value for x=%d node succeeded \ n", __function__,x);        return 1; } Pmove = pmove->next;    } printf ("%s function execution, delete node with value x ' failed \ n", __function__); return 0;}


C language implementation of non-cyclic doubly linked List node deletion (lead node tail junction)

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.