题解 | #牛牛的链表添加节点#

牛牛的链表添加节点

https://www.nowcoder.com/practice/e33b79c2e15a41f9b541e73cd256124a

#include <stdio.h>
#include<malloc.h>

typedef struct node {
    int data;
    struct node* next;
} node;
int main() {
    int n, i,s;
    scanf("%d %d", &n, &i);
    s=i;
    node* head = malloc(sizeof(node)), *t1 = head, *t2 = head;
    while (n--) {
        node* t = malloc(sizeof(node));
        scanf("%d", &t->data);
        t1->next = t;
        t1 = t;
    }
  //找到第i个节点
    while (i--) {
        t2 = t2->next;
    }
  //在该节点后面添加一个新节点
    node* t = malloc(sizeof(node));
    t->data = s;
    t->next = t2->next;
    t2->next = t;
    while (head->next) {
        printf("%d ", head->next->data);
        head = head->next;
    }
    return 0;
}

#C#
0基础学C 文章被收录于专栏

0基础学C,从算法开始

全部评论

相关推荐

03-12 09:57
软件测试
程序员小白条:1)确定测试,测开的方向,技术栈不能写这么少 2)课程凑数的,不是99,100分没必要写 3)实习经历这块要有突出的不是劳动性质的亮点,自己设计的什么方案,什么自动化?什么提效工具?不是一些边角料,人云亦云的东西,没吸引力 4) 校园经历纯没用 5)尽量少写减分项
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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