双向链表的建立就是在每个链表结点加上一个父指针和一个子指针,一个指向前一个结点,一个指向后一个结点。
#include<stdio.h>
#include<stdlib.h>
int n;
typedef struct node
{
struct node *pre;
int data;
struct node *next;
}link;
#define len sizeof(link)
link *creat()
{
link *head,*p1,*p2;
p1=p2=(link *)malloc(len);
scanf("%d",&p1->data);n=0;
while(p1->data!=0)
{
n++;
if(n==1) head=p1;
else{p2->next = p1; p1->pre = p2;}
p2=p1;
p1=(link *)malloc(len);
scanf("%d",&p1->data);
}
free((void*)p1);
p2->next=NULL;
return head;
}