# 单链表向双量表转换(线性表)

1 3 6 2 3 8 90

1 3 6 2 3 8 90

``3 5 6 7 8 2 3 4``

``3 5 6 7 8 2 3 4 ``

``````#include<stdio.h>
#include<stdlib.h>
struct f
{
int x;
struct f *prior,*next;
};
struct f *p;
int m;
struct f *f1()
{
while(p1=(struct f *)malloc(sizeof(struct f)),scanf("%d",&p1->x)!=EOF)
{
else
p2->next=p1;
p2=p1;
m++;
}
p2->next=NULL;
}
int main()
{
struct f *p1,*p2,*p;
p=f1();
for(p1=p;p1!=NULL;p1=p1->next )
{
p2=p1->next;
if(p2==NULL)
break;
p2->prior =p1;
p2=p1;
}
p1->next =p;
p->prior =p1;
while(m--)
{
printf("%d ",p->x);
p=p->next;
}

return 0;
}
``````

``````#include<stdio.h>
#include<stdlib.h>
struct f
{
int x;
struct f *prior,*next;
};
struct f *p;
int m;
struct f *f1()
{
while(p1=(struct f *)malloc(sizeof(struct f)),scanf("%d",&p1->x)!=EOF)
{
else
p2->next=p1;
p2=p1;
m++;
}
p2->next=NULL;
}
int main()
{
struct f *p1,*p2,*p;
p=f1();
for(p1=p;p1!=NULL;p1=p1->next )
{
p2=p1->next;
if(p2==NULL)
break;
p2->prior =p1;
p2=p1;
}
p1->next =p;
p->prior =p1;
while(m--)
{
printf("%d ",p->x);
p=p->next;
}

return 0;
}
``````