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;
}
An integer val.
Output the new linked list from which is removed all the nodes that equals to the input value.