Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <queue>
- #include <stack>
- #include <fstream>
- using namespace std;
- template<class T>
- void reverseQueue(queue<T>& Queue)
- {
- stack<T> Stack;
- while (!Queue.empty()) {
- Stack.push(Queue.front());
- Queue.pop();
- }
- while (!Stack.empty()) {
- Queue.push(Stack.top());
- Stack.pop();
- }
- }
- int main()
- {
- queue<string> Words;
- fstream in("input.txt", ios::in);
- while (in.peek() != EOF) {
- string s;
- in >> s;
- Words.push(s);
- }
- reverseQueue(Words);
- while (!Words.empty()) {
- cout << Words.front() << endl;
- Words.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement