题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
#include <iostream>
#include <forward_list>
using namespace std;
int main() {
int n = 0;
while(cin >> n){
forward_list<int> slist;
int head = 0;
int newnum = 0;
int oldnum = 0;
int pos = 0;
int de = 0;
cin >> head;
slist.push_front(head);
n--;
while(n--){
cin >> newnum >> oldnum;
forward_list<int>::iterator it;
it = slist.begin();
for(;it!=slist.end();it++){
if(*it==oldnum)
slist.emplace_after(it, newnum);
}
}
cin >> de;
slist.remove(de);
forward_list<int>::iterator it = slist.begin();
for(;it!=slist.end();it++){
cout << *it << ' ';
}
}
}
