#include <stdio.h>
#include "stdlib.h"
#define LEN sizeof (struct node)
struct node{
int data;
struct node *next;
}*p,*head;
void input(){
int num;
struct node* q;
printf("Enter data:");
scanf("%d",&num);
if(num<0)
return;
q=(struct node *) malloc(LEN);
q->data=num;
q->next=p;
p=q;
input();
}
int main() {
printf("Enter data >0\n");
p=NULL;
input();
head=p;
printf("Output:\n");
while (p){
printf("%d\n",p->data);
p=p->next;
}
return 0;
}
从键盘上输入整数,直到小于零结束,反序输出19-2
最新推荐文章于 2025-12-16 14:17:05 发布
该篇文章展示了如何使用C语言定义一个结构体表示链表节点,并实现了一个输入函数用于添加节点和主函数来遍历并输出链表中的数据。
569

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



