Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class Queue
- {
- private:
- struct Element
- {
- int inf;
- Element *next;
- Element(int x) : inf(x), next(0)
- {
- }
- };
- Element *head, *tail;
- public:
- Queue() : head(0), tail(0) {}
- bool Empty()
- {
- return head == 0;
- }
- int Get()
- {
- if (Empty())
- {
- return 0;
- }
- else
- {
- Element *t = head;
- int i = t->inf;
- head = t->next;
- if (head == 0)
- tail = 0;
- delete t;
- return i;
- }
- }
- void Put(int data)
- {
- Element *t = tail;
- tail = new Element(data);
- if (!head)
- {
- head = tail;
- }
- else
- {
- t->next = tail;
- }
- }
- };
- int main()
- {
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- Queue t, t1;
- int i;
- while (cin>>i)
- {
- t.Put(i);
- }
- while(!t.Empty())
- {
- i=t.Get();
- if ((i%2)==0)
- {
- t1.Put(i);
- t1.Put(i);
- }
- else t1.Put(i);
- }
- while (!t1.Empty())
- {
- cout<<t1.Get()<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement