Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <stack>
- #include <queue>
- #include <list>
- #include <exception>
- using namespace std;
- ifstream fin("input.txt");
- template <class Item>
- class Queue
- {
- struct Element
- {
- Item inf;
- Element *next;
- Element(Item x) : inf(x), next(0) {}
- };
- Element *head, *tail; //указатели на начало и конец очереди
- public:
- Queue() : head(0), tail(0) {}
- bool empty()//возвращает true, если очередь пуста, иначе false
- {
- return head == 0;
- }
- Item Get()
- {
- if (empty())
- cout << "QueueException: get - queue empty";
- else
- {
- Element *t = head;
- Item i = t->inf;
- head = t->next;
- if (head == NULL)
- tail = NULL;
- delete t;
- return i;
- }
- }
- void pop()
- {
- if (empty())
- cout << "Queue is empty!!!!!!!!!!!\n\n\n";
- Element *t = head;
- head = head->next;
- if (head == NULL)
- tail = NULL;
- delete t;
- }
- Item front()
- {
- return head->inf;
- }
- void push(Item data)
- {
- Element *t = tail;
- tail = new Element(data);
- if (!head)
- head = tail;
- else
- t->next = tail;
- }
- };
- int main()
- {
- /*
- 1 2 3 4 5 6
- */
- Queue<int> q;
- while (fin.peek() != EOF)
- {
- int cur;
- fin >> cur;
- q.push(cur);
- if (cur % 2 == 0)
- q.push(cur);
- }
- while (!q.empty())
- {
- int cur = q.front();
- q.pop();
- cout << cur << ' ';
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement