题目描述
删除单链表所有值为x的结点
样例
blablabla
算法1
C++ 代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
int val;
Node* next;
Node(int _val):val(_val),next(NULL){}
};
Node* removeAllXNode(Node* head,int x)
{
Node* pre = new Node(-1),*cur = head;
pre->next = cur;
head = pre;
while(cur)
{
if(cur->val == x)
{
pre->next = cur->next;
cur = cur->next;
}
else
{
pre = pre->next;
cur = cur->next;
}
}
return head->next;
}
int main()
{
//\\\\
removeAllXNode(head,x);
return 0;
}