Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- 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 Top()
- {
- if (Empty())
- {
- return 0;
- }
- else
- {
- return head->inf;
- }
- }
- };
- int main()
- {
- Stack q, w;
- int i;
- ifstream in("in.txt");
- ofstream out("out.txt");
- for (int i = 0; in >> i;i++)
- {
- if (i == 9)
- q.Push(i);
- else i++;
- }
- in.close();
- while (!q.Empty())
- {
- out << q.Pop() << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment