Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <stack>
- #include <queue>
- #include <list>
- #include <forward_list>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- // input.txt : 1 -5 2 3 -4 51 -14 -24 1 5
- int main()
- {
- forward_list<int> fl;
- while (in.peek() != EOF)
- {
- int cur; in >> cur;
- fl.push_front(cur);
- }
- forward_list<int> ans;
- forward_list<int> rev_temp;
- while (!fl.empty())
- {
- int cur = fl.front();
- fl.pop_front();
- if (cur < 0)
- ans.push_front(cur);
- else
- rev_temp.push_front(cur);
- }
- forward_list<int> temp;
- while (!rev_temp.empty())
- {
- int cur = rev_temp.front();
- rev_temp.pop_front();
- temp.push_front(cur);
- }
- while (!temp.empty())
- {
- int cur = temp.front();
- temp.pop_front();
- ans.push_front(cur);
- }
- for (auto v : ans)
- cout << v << " ";
- }
Add Comment
Please, Sign In to add comment