A TX pen question that deletes a specified node of a doubly linked list

Source: Internet
Author: User

DoubleLink.cpp: Defines the entry point of the console application. * Given a number, remove the number of nodes from this doubly linked list. If you have more than one of these nodes, just delete any one. Please give the function prototype and code implementation. *//* with the head node of the doubly linked list, I deleted the first sequential traversal, the discovery of the node I really vs2008 under the written. */#include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <windows.h>struct node {int Valu    E    struct node *priv; struct node *next;};/ * Set up a doubly linked list */struct node* create_double_link ();/* Deletes a doubly linked list of specified values */struct node* delete_double_link (struct node* head,int    Value), void Print_double_link (struct node* head), struct node* create_double_link () {struct node* head=null;    struct node* pcurrent=null;    struct node*ptemp=null;    int num=0,total=0;        Do {printf ("Please input the number: \ n");        scanf ("%d", &total);        if (total = = 0) printf ("Sorry,the number is error!\n");    else printf ("\ n");    }while (total = = 0);        while (num<total) {num=num+1;        pcurrent= (struct node*) malloc (sizeof (struct node)); if (pcurrent==null) {printf ("malloc error,please check it!\n");        Break        } else {pcurrent->value=num;            } if (num = = 1) {head=pcurrent;                pcurrent->priv=null;            } else {ptemp->next=pcurrent;        pcurrent->priv=ptemp;    } ptemp=pcurrent;    } ptemp->next=null; return (head);}    struct node* delete_double_link (struct node* head,int value) {struct node* pcurrent=null;    Pcurrent=head;        if (head==null) {printf ("Error:please Check the data!\n");    return (NULL); } else {while ((Value!=pcurrent->value) && (pcurrent->next!=null)) pcurrent=pcurrent        ->next;                if (value==pcurrent->value)//find It {if (Pcurrent==head)//is head node {                pcurrent->next->priv=null;                            head=pcurrent->next; } ElSe if (pcurrent->next==null)//wear {pcurrent->priv->next=null;                } else {pcurrent->priv->next=pcurrent->next;            pcurrent->next->priv=pcurrent->priv;            } free (pcurrent);        printf ("The NUM has been Deletea is:%d\n", value);        } else {printf ("Can not find the num:%d\n", value); }} return (head);}    void Print_double_link (struct node* head) {struct node* ptemp;        if (head = = NULL) {printf ("Error:have no data!\n");    Return    } Ptemp=head;        while (ptemp) {printf ("num:%d\n", ptemp->value);    ptemp=ptemp->next; } return;    int _tmain (int argc, _tchar* argv[]) {struct node* head,ptemp;    int num=0;    Head=create_double_link ();        Print_double_link (head);    printf ("Please input the delete num:\n");    scanf ("%d", &num); Head=delete_double_link (HEAD, num);    Print_double_link (head); Sleep (10000); return 0;}

A TX pen question that deletes a specified node of a doubly linked list

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.