建立链表程序。当输入0时表示链表输入结束,0不计入该链表。注意:只允许在/******start******/和/******end******/之间添加代码。
其中:
1 2 3 4 5 0
是键盘输入的。
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node * create();
void output(struct node *head);
int main()
{
struct node *head;
printf("Input:\n");
head = create();
printf("Output:\n");
output(head);
return 0;
}
struct node * create()
{
/******start******/
/******end******/
}
void output(struct node *head)
{
if (head == NULL)
{
printf("No data!\n");
return ;
}
while (head != NULL)
{
printf("%d ", head->data);
head = head->next;
}
printf("\n");
}
参考代码:
#include <stdio.h>