28 lines
699 B
C
Executable File
28 lines
699 B
C
Executable File
#include "stack.h"
|
|
|
|
//pushes an int onto the stack
|
|
int pushInt(stack_t *stack, int value) {
|
|
if(!ensure(stack)) return -1;
|
|
stack->elements[stack->top].i=value;
|
|
return (stack->top)++;
|
|
}
|
|
//pushes a double onto the stack
|
|
int pushDouble(stack_t *stack, double value) {
|
|
if(!ensure(stack)) return -1;
|
|
stack->elements[stack->top].d=value;
|
|
return (stack->top)++;
|
|
}
|
|
|
|
//pops an int from the stack
|
|
int popInt(stack_t *stack, int *value) {
|
|
if(empty(stack)) return -1;
|
|
*value=stack->elements[stack->top-1].i;
|
|
return --stack->top;
|
|
}
|
|
//pops a double from the stack
|
|
int popDouble(stack_t *stack, double *value) {
|
|
if(empty(stack)) return -1;
|
|
*value=stack->elements[stack->top-1].d;
|
|
return --stack->top;
|
|
}
|