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");
- class Stack
- {
- struct Element
- {
- int inf;
- Element *next;
- Element(int x, Element *p) : inf(x), next(p) {}
- };
- Element *head;
- public:
- Stack() : head(0) {}
- bool empty()
- {
- return head == 0;
- }
- int pop()
- {
- if (empty())
- {
- return 0;
- }
- Element *r = head;
- int i = r->inf;
- head = r->next;
- delete r;
- return i;
- }
- void push(int data)
- {
- head = new Element(data, head);
- }
- int Тор()
- {
- if (empty())
- {
- return 0;
- }
- else
- {
- return head->inf;
- }
- }
- };
- int main()
- {
- /*
- 1 2 3 4 5 6
- */
- Stack s;
- while (fin.peek() != EOF)
- {
- int cur;
- fin >> cur;
- s.push(cur);
- if (cur % 2 == 0)
- s.push(cur);
- }
- while (!s.empty())
- {
- int cur = s.pop();
- cout << cur << ' ';
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement