TITLE: PROGRAM ON STACK
#include<iostream.h>
#include<conio.h>
#define MAX 5
class stack
{
int arr[MAX];
int top;
public:
stack(){
top = -1;
}
void push (int X) {
if (top== MAX - 1)
{
cout<<"\nstack overflow!";}
else {
top++;
arr[top] = X;
cout << "\ninserted" << X << "into the stack.";
}
}
void pop(){
if (top == -1) {
cout<<"\nstack underflow!"; }
else {
cout << "\ndeleted element: "<< arr[top];
top--;
}
}
void display() {
if(top == -1) {
cout << "\nstack id empty!";
return;
}
cout << "\nstackelement are:\n";
int i=top;
while (i>=0) {
cout<<arr[i]<<" ";
i=i-1;
}
}
};
void main() {
clrscr ();
stack s;
int choice, val;
do {
cout<< "\n\n_ _ _ stack menu _ _ _";
cout<< "\[Link]";
cout<< "\[Link]";
cout<< "\[Link]";
cout<< "\[Link]";
cout<< "\nenter your choice:";
cin >> choice;
switch (choice) {
case 1:
cout << "enter value to push:";
cin >> val;
[Link](val);
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
cout<< "\nexiting_ _ _";
break;
default:
cout<< "ninvalid choice!";
}
}
while (choice !=4);
getch();
}
OUTPUT: