#include using namespace std; struct Node { int Data; Node *next; } *top; void popStack() { Node *temp, *var=top; if(var==top) { top = top->next; delete var; } else cout << endl << "Stack is Empty" << endl; } void push(int value) { Node *temp = new Node; temp->Data=value; if (top == NULL) { top=temp; top->next=NULL; } else { temp->next=top; top=temp; } } void display() { Node *var=top; if(var!=NULL) { cout << endl << "Elements are:" << endl; while(var!=NULL) { cout << var->Data << " "; var=var->next; } cout << endl; } else cout << endl << "Stack is Empty"; } int main(int argc, char *argv[]) { int i=0; top=NULL; cout << endl <<" 1. Push to stack"; cout << endl <<" 2. Pop from Stack"; cout << endl <<" 3. Display data of Stack"; cout << endl <<" 4. Exit" << endl; while(1) { cout << endl << " Choose Option: "; cin >> i; switch(i) { case 1: { int value; cout << "Enter a value to push into Stack: "; cin >> value; push(value); display(); break; } case 2: { popStack(); display(); break; } case 3: { display(); break; } case 4: { Node *temp; while(top!=NULL) { temp = top->next; delete top; top=temp; } exit(0); } default: { cout << endl << "Wrong choice..." << endl; } } } }