Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "stack.h"
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- Stack <int> getNumb;
- int i, x;
- cin >> x;
- while (in >> i)
- {
- getNumb.Push(i);
- }
- while (!getNumb.Empty())
- {
- if (x != getNumb.Top())
- out << getNumb.Top() << " ";
- getNumb.Pop();
- }
- in.close();
- out.close();
- return 0;
- }
- using namespace std;
- template <class Item>
- class Stack
- {
- private:
- struct Element
- {
- Item inf;
- Element *next;
- Element(Item x, Element *p) : inf(x), next(p) {}
- };
- Element *head;
- public:
- Stack() : head(0) {}
- bool Empty()
- {
- return head == 0;
- }
- Item Pop()
- {
- if (Empty())
- {
- return 0;
- }
- else
- {
- Element *r = head;
- Item i = r->inf;
- head = r->next;
- delete r;
- return i;
- }
- }
- void Push(Item data)
- {
- head = new Element(data, head);
- }
- Item Top()
- {
- if (Empty())
- {
- return 0;
- }
- else
- {
- return head->inf;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment