#include<stdio.h>
#include<malloc.h>
#define elemType int
//定义数据元素
typedef struct LNode{
elemType data; //数据域
struct LNode *next; //指针域
}LNode,*List;
//头插法创建单链表
List ListHeadInsert(List p){
List s;
int x;
p = (List)malloc(sizeof(LNode)); //创建空结点
p->next = NULL;
printf("请输入数据(以9999结束):\n");
scanf("%d",&x);
while(x!=9999){
s = (List)malloc(sizeof(LNode));
s->data = x;
s->next = p->next;
p->next=s;
scanf("%d",&x);
}
return p;
}
//打印单链表
List PrintList(List p){
printf("调用成功");
while(p){
printf("%d",p->data);
p=p->next;
}
// if(!p->next){
// printf("该单链表为空链表");
// }
return p;
}
int main(){
List p ;
ListHeadInsert(p);
printf("创建成功\n");
PrintList(p);
}