回复 2楼 voidx
那怎么弄啊
回复 6楼 烟雾中的迷茫
恩,谢谢啊
程序代码:#include <stdio.h>
#include <malloc.h>
typedef struct struct_node {
int data;
struct struct_node * next;
} node, * list;
int main() {
list l = (list) malloc(sizeof(node)); // 创建头结点
node * p = l;
int i;
printf("Give me the numbers you want to put into the list.\nAny none numerical character terminates the input.\n\n");
printf("Give me a integer to append to the end of the list: ");
fflush(stdout);
while (scanf("%d", &i)) { // 创建链表
p->next = (node *) malloc(sizeof(node));
p = p->next;
p->data = i;
printf("Give me a integer to append to the end of the list: ");
fflush(stdout);
}
p->next = l->next; // 最后一个结点的 next 指向第一个结点
p = l->next; // p 指向第一个结点
free(l); // 释放为头结点分配的空间
l = p; // l 指向第一个结点
do { // 显示循环链表中个个结点的数据
printf("%d ", p->data);
p = p->next;
} while (p != l);
return 0;
}