printf("请输入单链表的数据: ");
list = LinkedListCreatT();
for (start = list->next; start != NULL; start = start->next)
printf("%d",start->data);
printf("\n");
LinkedList LinkedListCreatT()
{
Node *L;
L = (Node *)malloc(sizeof(Node));
L->next = NULL;
Node *r;
r = L;
ElemType x;
while (scanf("%d", &x) != EOF)
{
Node *p;
p = (Node *)malloc(sizeof(Node));
p->data = x;
r->next = p;
r = p;
}
r->next = NULL;
return L;
}
有时候需要两个ctrl
ElemType 是什么类型?int? 和%d格式一致吗?
ctrl+z回车,可以退出循环。
也许是编译器的问题。加一个清除缓冲区试试:
while (scanf("%d", &x) != EOF)
{
fflush(stdin);
Node *p;
p = (Node *)malloc(sizeof(Node));
p->data = x;
r->next = p;
r = p;
}
你测试一下下面代码,如果ctrl+z能退出,就说明你的程序其他地方可能有错误。
#include <stdio.h>
void main()
{
int x;
while (scanf("%d", &x) != EOF)
{
printf("%d\n",x);
}
}