#include<iostream>
using namespace std;
int a;
typedef struct Node {
int data;
Node* next;
}Node;
typedef Node* List;
void tailinsert(List& h) {
List tail;
h = new Node;
h->next = NULL;
tail = h;
int x;
while (cin >> x && x) {
List p = new Node;
p->data = x;
p->next = NULL;
tail->next = p;
tail = p;
}
}
void dele(List& h) {
List prev, p;
prev = h;
p = h->next;
while (p) {
if (p->data == a) {
p = p->next;
prev->next = p;
}
else {
prev = prev->next;
p = p->next;
}
}
}
void prin(List& h) {
for (List i = h->next; i != NULL; i = i->next) {
cout << i->data << " ";
}
}
int main() {
List h;
tailinsert(h);
cin >> a;
dele(h);
prin(h);
return 0;
}
测试运行:
|