Skip to content

Instantly share code, notes, and snippets.

  • Save sameerkumar18/ea2b96b55dd772fb55ec to your computer and use it in GitHub Desktop.
Save sameerkumar18/ea2b96b55dd772fb55ec to your computer and use it in GitHub Desktop.
/*Ans 1. Create a menu driven program to provide the operations on linear stack: 1. Inserting Elements 2. Removing Elements 3. Display Stack Elements 4. Exit
Programmed By fb.com/sameer18051998*/
#include<iostream.h>
#include<conio.h>
#include<process.h>
int top=-1;
void push(int stack[5])
{
while(top<5)
{
if(top—=4)
cout<<"Stack Overflow";
break;
}
else
top+= 1;
cout<<"Value= ";
cin>>stack[top];
}
}
}
void pop(int stack[5]) {
if(top==-1)
cout<<"Stack underfiow";
else
{
cout<<"Removing the value "<<stack[top];
top-=1;
}
}
void display(int stack[5]) {
while(top>=0) {
if(top==-1) {
cout<<"Stack underfiow";
break;
}
else {
cout<<stack[top]<<",";
top-=1;
}
}
cout<<"\b"<<" ";
}
void main()
{
clrscr();
int stack[5],n,choice=0;
while(choice!=4)
{
clrscr();
cout<<"* * Stack calculator * * *";
cout<<"\nl. Inserting elements";
cout<<"\n2. Removing elements";
cout<<"\n3. Display elements";
cout<<"\n4. Exit";
cout<<"\n Enter your choice from 1-4= ";
cin>>choice;
switch(choice)
{
case 1:push(stack);
getch();
break;
case 2:pop(stack);
getch();
break;
case 3:display(stack);
getch();
break;
case 4:exit(0);
break;
default: cout<<"Invalid choice\n";
}
}
getch();
}
/*Programmed By fb.com/sameer18051998*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment