#include <iostream>#include<cstring>#include<cstdio>#include<stdlib.h>using namespaceStd;typedefstructstudent{intdata; structstudent*Next; structStudent *Pre;} Dnode;dnode*creat ()//establishment of doubly linked list{Dnode*head,*p,*s; intx,cycle=1; Head=NewDnode; P=Head; while(cycle) {printf ("Please enter data \ n"); scanf ("%d",&x); if(x<=0) Break; S=NewDnode; S->data=x; S->pre=p; P->next=s; P=s; } head=head->Next; Head->pre=NULL; P->next=NULL; returnHead;} Dnode*del (Dnode *head,intnum) {Dnode*s,*p,*P; S=Head; while(s->next!=NULL) { if(s->data==num) { if(s==head) {Head=head->Next; Head->pre=NULL; Deletes; returnHead; } Else if(s->next==NULL) {s->pre->next=NULL; Deletes; returnHead; } Else{p=s->Pre; Q=s->Next; Q->pre=p; P->next=Q; Deletes; }} s=s->Next; } if(s==NULL) printf ("The list doesn't have this number \ n"); Else returnhead;}voidPrint (Dnode *head)//single-linked list printing{Dnode*p=Head; P=Head; while(p!=NULL) {printf ("%d",p->data); P=p->Next; } printf ("\ n");}intMain () {Dnode*Head; intnum1,num2; Head=creat (); Print (head); printf ("Please enter the number to delete \ n"); scanf ("%d",&NUM1); Head=del (HEAD,NUM1); Print (head); return 0;}
Double linked list creation and deletion