题解 | #牛牛的单向链表#
牛牛的单向链表
https://www.nowcoder.com/practice/95559da7e19c4241b6fa52d997a008c4
#include <stdio.h> #include <malloc.h> typedef struct node { int data; struct node* next; } node; int main() { node* head = malloc(sizeof(node));//创建头节点 node* t = head;//创建临时节点用于输入数据 int a; scanf("%d", &a); while (a--) { scanf("%d", &t->data);//对临时节点操作 node* node = malloc(sizeof(node));//创建下一个节点 t->next = node; t = node; } while (head->next) {//遍历链表 printf("%d ", head->data); head = head->next; } return 0; }#C#
0基础学C 文章被收录于专栏
0基础学C,从算法开始