//定义一个单链表
typedef struct student
{
int data;
struct student *next;
}node;
node *create()
{
node *p,*s,*head;
int x,cycle = 0;
head = (node*)malloc(sizeof(node));
p = head;
while(cycle)
{
printf("please enter your data:\n");
scanf("%d",&x);
if(x!=0)//输入0则结束输入
{
s = (node*)malloc(sizeof(node));
s->data = x;
p->next = s;
p=s;
}
else
{
cycle = 0;
}
}
head = head ->next;//没有这句头结点中未存放数据
p->next = NULL;
return head;
}
单链表的建立,求长度,打印
最新推荐文章于 2024-01-20 17:44:52 发布
9552

被折叠的 条评论
为什么被折叠?



