#include <iostream>
using namespace std;
struct Node{
int data;
Node* pNext;
};
void deleteAtBeginning(Node* &pHead);
void deleteANode(Node*& pHead, int k);
void deleteAllNode(Node*& pHead, int k);
//-----------------------------------------------------//
void deleteAtBeginning(Node* &pHead) {
Node* cur = pHead;
if (pHead) pHead = pHead->pNext;
delete cur;
}
//-----------------------------------------------------//
void deleteANode(Node*& pHead, int k) {
if(pHead != nullptr && pHead->data == k) {
deleteAtBeginning(pHead);
return;
}
Node* tmp = nullptr;
Node* cur = pHead;
while(cur != nullptr && cur->data != k) {
tmp = cur;
cur = cur->pNext;
}
if (cur == nullptr) return;
tmp->pNext = cur->pNext;
delete cur;
}
//-----------------------------------------------------//
void deleteAllNode(Node*& pHead, int k) {
while (pHead != nullptr && pHead->data == k) deleteAtBeginning(pHead);
if (pHead == nullptr) return;
for (Node *cur = pHead; cur->pNext != nullptr; ) {
if(cur->pNext->data == k)
deleteAtBeginning(cur->pNext);
else
cur = cur->pNext;
}
}
//-----------------------------------------------------//
int main() {}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IE5vZGV7CiAgICBpbnQgZGF0YTsKICAgIE5vZGUqIHBOZXh0Owp9OwoKdm9pZCBkZWxldGVBdEJlZ2lubmluZyhOb2RlKiAmcEhlYWQpOwp2b2lkIGRlbGV0ZUFOb2RlKE5vZGUqJiBwSGVhZCwgaW50IGspOwp2b2lkIGRlbGV0ZUFsbE5vZGUoTm9kZSomIHBIZWFkLCBpbnQgayk7CgovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLy8KCnZvaWQgZGVsZXRlQXRCZWdpbm5pbmcoTm9kZSogJnBIZWFkKSB7CiAgICBOb2RlKiBjdXIgPSBwSGVhZDsKICAgIGlmIChwSGVhZCkgcEhlYWQgPSBwSGVhZC0+cE5leHQ7CiAgICBkZWxldGUgY3VyOwp9CgovLy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