Skip to content

Instantly share code, notes, and snippets.

@aswanthkoleri
Created April 12, 2017 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aswanthkoleri/6e41d4712fc832b8ed2170559c38c327 to your computer and use it in GitHub Desktop.
Save aswanthkoleri/6e41d4712fc832b8ed2170559c38c327 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int isempty(int top)
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
int isfull(int top,int n)
{
if(top==(n)-1)
{
return 1;
}
else
{
return 0;
}
}
void push(int st[],int *top,int data,int n)
{
if(isfull(*top,n))
{
printf("pushing not possible");
}
else
{
*top++;
st[*top]=data;
}
}
int pop(int st[],int *top){
int temp;
if(isempty(*top))
{
return printf("the pop operation is not possible ");
}
else
{
temp=st[*top];
*top--;
return temp;
}
}
int main()
{
int st[50],n,st,top=-1;
printf("enter the stacksize");
scanf("%d",&n);
push(st,top,4,n);
push(st,top,5,n);
push(st,top,6,n);
push(st,top,7,n);
push(st,top,8,n);
pop(st,top);
pop(st,top);
printf("The stack is ");
for(i=0;i<(top+1);i++)
{
printf("%d",st[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment