Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node
- {
- public:
- int get()
- {
- return this->Object;
- }
- void set(int value)
- {
- this->Object = value;
- }
- void setNext(Node* value)
- {
- this->nextNode = value;
- }
- Node *getNext()
- {
- return this->nextNode;
- }
- private:
- int Object;
- Node* nextNode;
- };
- class Stack
- {
- public:
- Stack()
- {
- headNode = new Node;
- headNode->setNext(NULL);
- headNode->set(-1);
- }
- void push(int value)
- {
- Node *newNode = new Node;
- newNode->set(value);
- newNode->setNext(headNode);
- headNode = newNode;
- }
- bool isEmpty()
- {
- if((headNode->get()) != -1)
- {
- return true;
- }
- if((headNode->get()) == -1)
- {
- return false;
- }
- }
- int pop()
- {
- if(isEmpty() != false)
- {
- int x = headNode->get();
- Node *p = headNode;
- headNode = headNode->getNext();
- delete p;
- return x;
- }
- if(isEmpty() != true)
- {
- cout << "Stack is Empty";
- return 0;
- }
- }
- private:
- Node * headNode;
- };
- main()
- {
- Stack stk;
- stk.push(23);
- stk.push(232);
- cout << stk.pop();
- system("pause");
- }
Add Comment
Please, Sign In to add comment