题解 | #从单向链表中删除指定值的节点# list容器
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
#include <iostream> #include <list> using namespace std; int main() { int n,he; cin >> n >> he; list<int> mylist; auto f = mylist.begin(); mylist.insert(f,he); for(int i=0; i<n-1; i++){ int a,b; cin >> a >> b; for(auto k = mylist.begin(); k != mylist.end(); k++){ if(*k == b){ mylist.insert(++k, a); break; } } } int tar; cin >> tar; for(auto k = mylist.begin(); k != mylist.end(); k++){ if(*k == tar){ mylist.erase(k); break; } } for(auto k = mylist.begin(); k != mylist.end(); k++){ cout << *k << ' '; } return 0; } // 64 位输出请用 printf("%lld")