题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
http://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
#include <algorithm>
#include <deque>
using namespace std;
int main() {
int x;
while(cin>>x){
deque<int> list;
int head;
cin>>head;
list.push_back(head);
for(int i = 0;i<(x-1);i++){
int first,second;
cin>>first>>second;
if(second==head) list.insert(++list.begin(), first);
else{
auto it = find(list.begin(),list.end(),second);
if(it == list.end()) list.push_back(first);
else list.insert(it+1,first);
}
}
int delet_int;
cin>>delet_int;
auto it = find(list.begin(),list.end(),delet_int);
list.erase(it);
for(auto itor:list){
cout<<itor<<' ';
}
}
}