求解为什么不行哇
#include<stdio.h>#include<stdlib.h>
#define NULL 0
#define Linkedlist struct sl
Linkedlist
{
int data;
Linkedlist *next;
};
void Create_Linkedlist(Linkedlist *h)
{
int i,x,n;
Linkedlist *p,*s;
printf("要存入几个数值?\n");fflush(stdout);
p=h;
p=(Linkedlist*)malloc(sizeof(Linkedlist));
s=(Linkedlist*)malloc(sizeof(Linkedlist));
scanf("%d",&n);
printf("请输入:");
for(i=1;i<=n;i++)
{
scanf("%d\n",&x);
s->data=x;
if(h->next==NULL)
h->next=s;
else
p->next=s;
p=s;
}fflush(stdout);
printf("已经存储成功");
p->next=NULL;
}
Linkedlist *Insert_Linkedlist(Linkedlist *h)
{
int i,j,x;
Linkedlist *p,*s;
s=(Linkedlist*)malloc(sizeof(Linkedlist));
p=(Linkedlist*)malloc(sizeof(Linkedlist));
p=h;
printf("请输入要插入的位置\n");
scanf("%d",&i);
printf("请输入要插入的数值\n");
scanf("%d",&x);
for(j=1;j<i;j++)
p=p->next;
s->data=x;
s->next=p->next;
p->next=s;
return h;
}
Linkedlist * Delete_Linkedlist(Linkedlist *h)
{
int i,j;
Linkedlist *p;
p=(Linkedlist*)malloc(sizeof(Linkedlist));
p=h;
printf("请输入要删除的位置\n");
scanf("%d",&i);
for(j=1;j<i;j++)
p=p->next;
p->next=(p->next)->next;
return h;
}
void Printf_Linkedlist(Linkedlist *h)
{
int i=1;
Linkedlist *p;
p=(Linkedlist*)malloc(sizeof(Linkedlist));
p=h->next;
for(p=h->next;(p->next)!=NULL;p=p->next)
printf("a[%d]=%d",i++,p->data);
}
int menu_select()
{
char c;
do
{
printf("请选择操作:\n1:创建单链表\n2:插入数据\n3:删除数据\n4:输出数据\n5:退出\n");
c=getchar();
}while(c<'1'||c>'5');
return (c-'0');
}
main()
{
Linkedlist *H;
H=(Linkedlist*)malloc(sizeof(Linkedlist));
H->next=NULL;
for( ;; )
{
switch(menu_select())
{
case 1:
Create_Linkedlist(H);break;
case 2:
Insert_Linkedlist(H);break;
case 3:
Delete_Linkedlist(H);break;
case 4:
Printf_Linkedlist(H);break;
case 5:
printf("Goodbye");exit(0);
}
system("cls");
}
}