各位大犇求帮忙康康代码!!谢谢!!!!!
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
struct node{
int val;
struct node* next;
};
void insertNode(int x, int y, node* head)
{
node* nod = (node*)malloc(sizeof(node));
nod->val = y;
nod->next = NULL;
while (head->next && head->val != x)
head = head->next;
head->next = nod;
}
void askNode(int x, node* head)
{
while (head->next && head->val != x)
head = head->next;
if (head->next == NULL)
cout << "0" << "\n";
else
cout << head->next->val << "\n";
}
void eraseNode(int x, node* head)
{
while (head->next && head->val != x)
head = head->next;
if (head->next)
head->next = head->next->next;
}
int main()
{
IOS;
int n;
cin >> n;
int op, x, y;
node* nod = (node*)malloc(sizeof(node));
nod->val = 1;
nod->next = NULL;
for (int i=0;i<n;i++)
{
cin >> op;
switch (op)
{
case 1:
cin >> x >> y;
insertNode(x, y, nod);
break;
case 2:
cin >> x;
askNode(x, nod);
break;
case 3:
cin >> x;
eraseNode(x, nod);
break;
}
}
return 0;
}