Files
ee/ee_stack.h
Jon-William Lewis 465ee17549 Initial Commit
2016-03-28 00:36:40 -05:00

40 lines
1023 B
C

struct EE_STACK_NODE {
double datum;
struct EE_STACK_NODE* tail;
};
typedef struct EE_STACK_NODE NODE;
typedef struct EE_STACK_NODE* STACK;
STACK
push(double datum, STACK tail){
/* Given a double value (datum), and a STACK (tail),
* push(datum,tail) is the STACK resulting from
* prepending datum to the STACK tail.
*/
NODE* new_node = (NODE*)malloc(sizeof(NODE));
(*new_node).datum = datum;
(*new_node).tail = tail;
return new_node;
}
STACK
pop(STACK target_stack){
/* Given a STACK (target_stack), pop(target_stack)
* is the STACK resulting from the removal of the first
* item in target_stack;
*/
if (target_stack == NULL){ return target_stack; }
STACK tail = (*target_stack).tail;
free(target_stack);
return tail;
}
double
peek(STACK target_stack){
/* Given a STACK (target_stack), peek(STACK)
* is the first element's datum.
*/
if (target_stack == NULL){ return 0; }
return (*target_stack).datum;
}