连接没有错误,可是为啥运行显示出错。。。求指教
#include<stdio.h>#include<malloc.h>
typedef struct node
{
int data;
struct node *next,*prior;
}listnode,*linklist;
void printlist(linklist head);
void initial(linklist head);
void creatlist(linklist head,int n);
void main()
{
linklist l;
initial(l);
int n;
printf("please enter number(N):");
scanf("%d",&n);
printf("please output the elements of linklist:");
creatlist(l,n);
printlist(l);
}
void printlist(linklist head)
{
listnode *p;
p=head->next;
while(p!=head)
{
printf("%4d",p->data);
p=p->next;
}
}
void initial(linklist head)
{
listnode *p;
p=head;
p->next=head;
p->prior=head;
}
void creatlist(linklist head,int n)
{
listnode *p,*t;
int i=1;
int x;
p=head;
while(i<=n)
{
if(i==n)
{
printf("please the latest element of linklist:");
scanf("%4d",&x);
t=(listnode*)malloc(sizeof(listnode));
t->data=x;
p->next=t;
t->prior=p;
t->next=head; //最后一个节点,要与头结点连接,并且头结点的前驱是最后一个结点
head->prior=t;
}
else
{
printf("please enter the element of linklist:");
scanf("%4d",&x);
t=(listnode*)malloc(sizeof(listnode));
t->data=x;
t->next=p->next;
t->prior=p;
p->next->prior=t;
p->next=t;
}
p=p->next;
i++;
}
}