为什么我的这段代码执行不起来,显示有段错误啊
#include <iostream>
using namespace std;
typedef struct LinkList {
int val = 0;
struct LinkList* next = nullptr;
} LinkList;
LinkList head;
void out_all();
void insert_node(int x, int y);
void delete_node(int x);
int main() {
int n = 0;
cin >> n;
int i = 0;
for (; i != n; ++i) {
string tmp;
cin >> tmp;
// cout<<tmp;
if (tmp == "insert") {
// cout << tmp;
int x, y;
cin >> x, y;
insert_node(x, y);
} else if (tmp == "delete") {
int x;
cin >> x;
delete_node(x);
}
}
out_all();
return 0;
}
void out_all() {
LinkList* tmp = head.next;
if (tmp == nullptr) {
cout << "null" << endl;
return ;
}
while (tmp) {
cout << tmp->val << ' ';
tmp = tmp->next;
}
}
void insert_node(int x, int y) {
if (head.next == nullptr) {
head.next = new LinkList;
head.next->val = y;
return ;
}
// out_all();
LinkList* tmp = head.next;
LinkList* pre = nullptr;
LinkList* node = new LinkList;
node->val = y;
out_all();
while (tmp && tmp->val != x) {
pre = tmp;
tmp = tmp->next;
}
// out_all();
node->next = pre->next;
pre->next = node->next;
return;
}
void delete_node(int x) {
if (head.next == nullptr) {
return ;
}
LinkList* tmp = head.next;
LinkList* pre = nullptr;
while (tmp && tmp->val != x) {
pre = tmp;
tmp = tmp->next;
}
if (pre->next != nullptr) {
cout << " get in " << endl;
LinkList* post = pre->next;
cout << post->val;
pre->next = post->next;
}
return;
}
// 64 位输出请用 printf("%lld")