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

牛牛的链表删除

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

#include <iostream>
using namespace std;
struct Node
{
    int num;
    Node* next;
};

void bulid_link_list(Node* dummy_head, int n)
{
    Node* temp = new Node;
    temp =  dummy_head;
    for(int i=0;i < n;i++)
    {
        Node* cur = new Node;
        temp->next = cur;
        cin >> cur->num;
        temp = temp->next;
    }
    temp->next = NULL;
}


void print(Node* dummy_head)
{
    Node* temp = new Node;
    temp = dummy_head->next;
    while (temp != NULL)
    {
        cout << temp->num << " ";
        temp = temp->next;
    }
}


int main()
{
    int n;
    cin >> n;
    int val;
    cin >> val;
    Node* dummy_head_a = new Node;
    bulid_link_list(dummy_head_a, n);
    Node* cur = dummy_head_a;
    while(cur != NULL && cur->next != NULL)
    {
        if (cur->next->num == val)
        {
            cur->next = cur->next->next;
        }
        cur = cur->next;
    }
    print(dummy_head_a);
    
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:45
你不要过来啊啊啊啊啊啊啊
码农索隆:对面:“今天你不面也得面”
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
07-09 18:33
门头沟学院 Java
这么逆天每年都有人去???&nbsp;填多益网申就是大型的服从性测试
鲁大牛:辅导员在群里发了这个公司我就申了一下。网申居然要写当场开摄像头写两篇不少于三百字的作文。太逆天了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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