#include <stdio.h>
#include <stdlib.h>
struct Node
{
int num;
struct Node *next;
};
int main(void)
{
struct Node *head,*tail, *p;
int num;
int size = sizeof(struct Node);
head=tail=NULL;
printf("请输入编号:\n");
scanf("%d", &num);
/*建立单向链表*/
while(num != 0)
{
p = (struct Node *) malloc(size);
p->num = num;
p->next=NULL;
tail->next=p;
tail=p;
scanf("%d", &num);
}
/*输出单向链表*/
printf("The single linked list is:\n");
for(p=head; p->next!=NULL; p=p->next)
printf("%d\n", p->num);
return 0;
}
原题
下面程序功能如下:输入若干个整数编号,输入编号为0时结束,用单向链表组织这些编号信息后,再按顺序输出。