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

牛牛的单向链表

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

全部评论

相关推荐

认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-18 16:32
quench@0916:一顿操作猛如虎,一看工资2500
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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