Skip to content

Instantly share code, notes, and snippets.

@iamirulofficial
Created February 23, 2019 18:32
Show Gist options
  • Save iamirulofficial/c700705addfe6a5d0ee4d6da50db6b1e to your computer and use it in GitHub Desktop.
Save iamirulofficial/c700705addfe6a5d0ee4d6da50db6b1e to your computer and use it in GitHub Desktop.
#include<stdio.h>
int stack[100],choice,n,top,i,x;
void push();
void pop();
void display();
int main(){
top=-1;
printf("\nEnter the size of the stack,maximum 100");
scanf("%d",&n);
printf("\nChoose number for operation\n\t 1.PUSH \n\t 2.POP \n\t 3.DISPLAY\n\tEnter 4 to exit the function\n");
do
{
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
printf("Exited");
break;
}
default:
{
printf("\nEnter valid choice");
}
}
}
while(choice !=4);
return 0;
}
void push(){
if(top>=n-1)
{
printf("\nSTACK is full");
}
else
{
printf("\nEnter element");
scanf("%d",&x);
top++;
stack[top]=x;
}
printf("Enter next choice:1/2/3/4");
}
void pop(){
if(top<=-1)
{
printf("\nstack is empty");
}
else
{
printf("\n the popped element is %d",stack[top]);
top--;
}
printf("Enter next choice 1/2/3/4");
}
void display(){
if(top>=0)
{
printf("\nelements");
for(i=top;i>=0;i--)
printf("\n%d",stack[i]);
printf("\npress next choice 1/2/3/4");
}
else
{
printf("\n STACK is empty");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment