Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <list>
- using namespace std;
- int main (void)
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- int x, y;
- int a;
- list <int> ls;
- list <int>::iterator i;
- while (in >> a)
- ls.push_back(a);
- y = ls.back();
- ls.pop_back();
- x = ls.back();
- ls.pop_back();
- for (i = ls.begin(); i != ls.end();)
- {
- a = *i;
- if (a == x)
- {
- i++;
- ls.insert(i, y);
- }
- else
- i++;
- }
- for (i = ls.begin(); i != ls.end(); i++)
- out << *i << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment