题解 | #牛牛的单向链表#

牛牛的单向链表

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,从算法开始

全部评论

相关推荐

05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务