Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Node {
- public:
- int data;
- Node *next;
- Node(int val, Node *next)
- {
- this->data = val;
- this->next = next;
- }
- };
- class Stack {
- private:
- Node * head;
- public:
- Stack()
- {
- this->head = NULL;
- }
- void push(int data)
- {
- Node *new_Node = new Node(data,this->head);
- this->head = new_Node;
- }
- int pop()
- {
- if (this->head != NULL)
- {
- int tmp = this->head->data;
- this->head = this->head->next;
- return tmp;
- }
- return NULL;
- }
- };
- int main()
- {
- Stack *st = new Stack();
- for (int i = 0; i < 10; i++)
- st->push(i);
- int d = st->pop();
- while (d)
- {
- cout << d << endl;
- d = st->pop();
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement