(双链表就是双向的链表,有前驱和后继)
建立时注意要开空间
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
typedef struct student
{
int data;
struct student *next;
struct student *pre;
} dnode;
//建立双链表
dnode* create()){
dnode *head,*p,*s;
int x,cycle=1;
head=(dnode*)malloc(sizeof(dnode));
p=head;
while(cycle){
printf("\n pleaseinput the data");
scanf("\n%d",&x);
if(x!=0){
s=(dnode*)malloc(sizeof(dnode));
s->data=x;
p->next=s; //s是p的后继
s->pre=p; //p是s的前驱
p=s; //p向后
}
else cycle=0;
}
head=head->next;
head->pre=NULL;
p->next=NULL;
//printf("\n yyy %d",head->data);
return (head);
}