Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- template <class T>
- class Queue {
- struct node {
- T data;
- node *next;
- node(string x, node *p) : data(x), next(p){}
- };
- node* head;
- node* tail;
- public:
- Queue() : head(0), tail(0){}
- bool Empty() { //проверка на пустоту стека
- return head == 0;
- }
- void Push(T data) { // добавляем элемент
- node* r = new node(data, nullptr);
- if (tail == nullptr) {
- head = tail = r;
- }
- else {
- tail->next = r;
- tail = r;
- }
- }
- T Top() {
- return head->data;
- }
- T Pop() {
- node* r = head;
- head = head->next;
- T g = r->data;
- delete r;
- if (head == nullptr) {
- tail = nullptr;
- }
- return g;
- }
- };
- int main() {
- Queue <string> t, t1;
- string s;
- while (in >> s) {
- t.Push(s);
- }
- in.close();
- while (!t.Empty()) {
- string i = t.Pop();
- t1.Push(i);
- if (i.size() == 1) {
- t1.Push(i);
- }
- }
- while (!t1.Empty()) {
- out << t1.Pop() << endl;
- }
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement