#include<stdio.h>
#include<stdlib.h>
struct NODE{
int date;
struct NODE *next;
};
typedef struct NODE node;
node *creat()
{
node *head,*p,*q;
int t;
head=malloc(sizeof(node));
p=head;
while(1)
{
scanf("%d",&t);
if(t<0) break;
q=malloc(sizeof(node));
q->date=t;
p->next=q;
p=q;
}
p->next=NULL;
return head;
}
void print(node *head)
{
node *p;
p=head->next;
if(p==NULL) printf("空集");
else
{
while(p!=NULL){
printf("%d ",p->date);
p=p->next;
}
}
}
int main()
{
node *h;
h=creat();
print(h);
return 0;
}
链表的遍历(C语言) 自用
于 2024-02-04 12:26:42 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)