Skip to content

Instantly share code, notes, and snippets.

@sharth
Created April 16, 2014 13:24
Show Gist options
  • Save sharth/3f67f2790e6a337ada47 to your computer and use it in GitHub Desktop.
Save sharth/3f67f2790e6a337ada47 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#define STACKSIZE 5
struct stack
{
float data[STACKSIZE];
int sp;
};
struct stack sta={{0},-1};
//push method
void push(float n)
{
sta.data[++sta.sp]=n;
}
//pop method
float pop()
{
return sta.data[sta.sp--];
}
//top method
float top()
{
return sta.data[sta.sp];
}
//full method
int full()
{
return (sta.sp==STACKSIZE-1);
}
//empty method
int empty()
{
return (sta.sp==-1);
}
int main()
{
int x;
float temp;
for (x=0; x<STACKSIZE; x++)
{
printf("Enter float to be stored in the stack: ");
scanf("%f", &temp);
push(temp);
}
while(!empty())
printf("%f\n",pop());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment