C 的 链表节点
等级 4249 次按键
创建简单的链表结构并使用while循环遍历它。
C 代码
// 用于链表的自引用结构体1struct Node {2 int data; // 指向下一个节点的指针3 struct Node *next;4};5 // 先创建最后一个节点,前面的节点才能取它的地址6struct Node n3 = {30, NULL};// n2指向n37struct Node n2 = {20, &n3};// n1指向n28struct Node n1 = {10, &n2};9 // 从第一个节点开始遍历10struct Node *curr = &n1;// 循环直到到达NULL11while (curr != NULL) { // 打印当前节点的数据12 printf("%d -> ", curr->data); // 移动到下一个节点13 curr = curr->next;14}// 在最后一个节点之后标出链表结尾15printf("NULL\n");运行结果
10 -> 20 -> 30 -> NULL
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C 代码中需要输入的符号及其出现次数。
;× 10=× 6{× 5}× 5,× 4"× 4-× 3(× 3)× 3&× 3