Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <list>
- using namespace std;
- template <typename T1, typename T2>
- list<T1> createList(T2& in) {
- T1 x;
- list<T1> lst;
- while (in >> x && in.peek() != '\n') {
- lst.push_back(x);
- }
- lst.push_back(x);
- return lst;
- }
- template <typename T>
- void reformList(T x, T y, list<T>& lst) {
- for (auto it = lst.begin(); --it != lst.end(); ++it) {
- if (*it == x) lst.insert(++it, y);
- }
- }
- template <typename T>
- void printList(list<T>& lst) {
- for (auto elem : lst) {
- cout << elem << " ";
- }
- cout << endl;
- }
- int main() {
- ifstream in("input.txt");
- list<int> lst = createList<int>(in);
- int x, y;
- in >> x >> y;
- reformList(x, y, lst);
- printList(lst);
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement