2598 - DS_22_TSAY_Exam_Week5 Scoreboard

Time

2022/10/13 10:10:00 2022/10/13 11:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13641 Remove

13641 - Remove   

Description

Given a linked list and a given value, remove all the nodes from the linked list that has data = value. Return the new list. Fill in the blanks marked "TODO".

#include <iostream>
using namespace std;

struct listNode
{
    int value;
    listNode* next;
    listNode(int x)
    {
        value = x;
        next = NULL;
    }
};

void print(listNode* head)
{
    //TODO
}

listNode* removeElements(listNode* head, int val) {
    //TODO
}

int main() {
    int val;
    cin >> val;

    listNode* head = new listNode(1);
    head->next = new listNode(2);
    head->next->next = new listNode(2);
    head->next->next->next = new listNode(3);
    head->next->next->next->next = new listNode(4);
    head->next->next->next->next->next = new listNode(5);
    head->next->next->next->next->next->next = new listNode(5);
    head->next->next->next->next->next->next->next = new listNode(10);

    print(removeElements(head, val));
    return 0;
}

Input

An integer val.

Output

Output the new linked list from which is removed all the nodes that equals to the input value.

Sample Input  Download

Sample Output  Download

Tags




Discuss