-
-
Save sharth/3f67f2790e6a337ada47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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