谁能帮忙看一下以下这个程序为什么运行后输入指定的Y或N后就出错了呢
#include"stdio.h"#include"process.h"
#include"stdlib.h"
#include"time.h"
#define size 10
struct LIST * reverse(struct LIST *head);
struct LIST
{
int data;
struct LIST *next;
}*head,*list,*temp;
void main()
{
int i;
char y_or_n;
time_t t;
srand((unsigned)time(&t));
list=head=(struct LIST*)malloc(sizeof(struct LIST));
if(list==NULL)
exit(1);
printf("如果您想手动输入数据,请输入Y;如果您想自动填充随即数据,请输入N:");
getchar();
y_or_n=getchar();
if(y_or_n=='y'||y_or_n=='Y')
for(i=0;i<size;i++)
{
scanf("%d",&list->data);
list->next = (i == size-1) ? NULL :(struct LIST*)malloc(sizeof(struct LIST));
list=list->next;
}
if(y_or_n=='n'||y_or_n=='N')
for(i=0;i<size;i++)
{
list->data=rand()%20;
list->next = (i == size-1) ? NULL :(struct LIST*)malloc(sizeof(struct LIST));
list=list->next;
}
list=head;
puts("\n链表倒置前:");
while(list)
{
printf("%4d",list->data);
list=list->next;
}
printf("\n");
puts("\n链表倒置后:");
list= reverse(head);
while(list)
{
printf("%4d",list->data);
list=list->next;
}
printf("\n");
}
struct LIST * reverse(struct LIST *head)//*倒置*//
{
list=head;
head = NULL ;
//head->data=NULL;
while(list)
{
temp=list->next;
list->next = head ;
head = list ;
list = temp ;
}
return head;
}