#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define len sizeof(struct doublelist)
struct doublelist{
int data;
struct doublelist *perior,*next;
};
struct doublelist *creat()
{
struct doublelist *p1,*p2,*head;
head=p1=(struct doublelist*)malloc(len);
p1->perior=NULL;
scanf("%d",&p1->data);
int n=0;
while(p1->data!=0)
{
if(n==0)
n++;
else
p2->next=p1,p1->perior=p2;
p2=p1;
p1=(struct doublelist*)malloc(len);
scanf("%d",&p1->data);
}
p2->next=NULL;
return head;
}
int main()
{
struct doublelist *L;
printf("构建链表L,以0结束:\n");
L=creat();
while(L!=NULL)
{
printf("%d ",L->data);
L=L->next;
if(L!=NULL)
printf("%d ",L->perior->data);
}
}
#include<stdlib.h>
#include<string.h>
#define len sizeof(struct doublelist)
struct doublelist{
int data;
struct doublelist *perior,*next;
};
struct doublelist *creat()
{
struct doublelist *p1,*p2,*head;
head=p1=(struct doublelist*)malloc(len);
p1->perior=NULL;
scanf("%d",&p1->data);
int n=0;
while(p1->data!=0)
{
if(n==0)
n++;
else
p2->next=p1,p1->perior=p2;
p2=p1;
p1=(struct doublelist*)malloc(len);
scanf("%d",&p1->data);
}
p2->next=NULL;
return head;
}
int main()
{
struct doublelist *L;
printf("构建链表L,以0结束:\n");
L=creat();
while(L!=NULL)
{
printf("%d ",L->data);
L=L->next;
if(L!=NULL)
printf("%d ",L->perior->data);
}
}