Advertisement
Infiniti_Inter

15 DoubleLinkedList

Nov 13th, 2019
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <stack>
  5. #include <queue>
  6. #include <list>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. ifstream in("input.txt");
  13. ofstream out("output.txt");
  14.  
  15. // input.txt : 1 -5 2 3 -4 51 -14 -24 1 5
  16.  
  17. int main()
  18. {
  19.     list<int> l;
  20.     while (in.peek() != EOF)
  21.     {
  22.         int cur; in >> cur;
  23.         l.push_back(cur);
  24.     }
  25.     list<int> ans;
  26.     list<int> temp;
  27.     out << "result : ";
  28.     while (!l.empty())
  29.     {
  30.         int cur = l.front(); l.pop_front();
  31.         if (cur > 0)
  32.         {
  33.             ans.push_back(cur);
  34.             out << cur << ' ';
  35.         }
  36.         else
  37.             temp.push_back(cur);
  38.  
  39.     }
  40.     while (!temp.empty())
  41.     {
  42.         int cur = temp.front(); temp.pop_front();
  43.         out << cur << ' ';
  44.         ans.push_back(cur);
  45.     }
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement