Advertisement
Infiniti_Inter

с 74 № 20(queue)

Apr 11th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <queue>
  4. #include <stack>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8. template<class T>
  9. void reverseQueue(queue<T>& Queue)
  10. {
  11.     stack<T> Stack;
  12.     while (!Queue.empty()) {
  13.         Stack.push(Queue.front());
  14.         Queue.pop();
  15.     }
  16.     while (!Stack.empty()) {
  17.         Queue.push(Stack.top());
  18.         Stack.pop();
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     queue<string> Words;
  25.     fstream in("input.txt", ios::in);
  26.     while (in.peek() != EOF) {
  27.         string s;
  28.         in >> s;
  29.         Words.push(s);
  30.     }
  31.     reverseQueue(Words);
  32.     while (!Words.empty()) {
  33.         cout << Words.front() << endl;
  34.         Words.pop();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement