题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
// HJ48-2 从单向链表中删除指定值的节点.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream>
#include<bits/stdc++.h>
#include<forward_list>
using namespace std;
int main()
{
int head, n;
cin >> n >> head;
forward_list<int>list;
list.push_front(head);
for (int i = 1; i < n; i++)
{
int front, back;
cin >> back >> front;
auto it = find(list.begin(),list.end(), front);
list.insert_after(it,back);
}
int back;
cin >> back;
list.remove(back);
for (auto it = list.begin(); it != list.end(); it++)
{
cout << *it << " ";
}
return 0;
}
