题解 | #牛牛的链表删除#

牛牛的链表删除

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

#include<stdio.h>

#include<stdlib.h>

typedef struct Node

{

    int date;

    struct Node* next;

} Node, *List;

int main()

{

    List L = (List)malloc(sizeof(Node));//创建头结点

    int n = 0, x = 0;

    scanf("%d%d", &n, &x);

    Node* temp = L;

    for (int i = 0; i < n; i++)

    {

        Node* a = (Node*)malloc(sizeof(Node));

        scanf("%d", &a->date);

        a->next = NULL;

        temp->next = a;

        temp = a;

    }//初始化,给链表赋值

    temp = L;

    while (temp->next)

    {

        if (temp->next->date == x)

        {

            temp->next = temp->next->next;

            continue;

        }

        else

            temp = temp->next;

        printf("%d "temp->date);

    }//删除链表元素,并打印

    return 0;

}

全部评论

相关推荐

就在我现在公司的隔壁每天经过都唏嘘不已(就是羡慕)什么时候可以到这里上班啊
柯基在debug:从大学毕业投简历到现在了,应届的时候我都面到终面了,现在工作四年了连简历初筛都过不了了
投递莉莉丝游戏等公司8个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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