/*--------------------------------------------------------------------*/ /* stack.h (Version 1) */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #ifndef STACK_INCLUDED #define STACK_INCLUDED /* A Stack is a last-in-first-out collection of doubles. */ struct Stack { /* The array in which items are stored. */ double *pdArray; /* The index one beyond the top element. */ int iTop; /* The number of elements in the array. */ int iPhysLength; }; struct Stack *Stack_new(void); /* Return the address of a new Stack. */ void Stack_free(struct Stack *psStack); /* Free psStack. Do nothing if psStack is NULL. */ void Stack_push(struct Stack *psStack, double dItem); /* Push dItem onto *psStack. It is a checked runtime error for psStack to be NULL. */ double Stack_top(struct Stack *psStack); /* Return the top item of *psStack. It is a checked runtime error for psStack to be NULL or for *psStack to be empty. */ void Stack_pop(struct Stack *psStack); /* Pop *psStack and discard the popped item. It is a checked runtime error for psStack to be NULL or for *psStack to be empty. */ int Stack_isEmpty(struct Stack *psStack); /* Return 1 (TRUE) iff *psStack is empty. It is a checked runtime error for psStack to be NULL. */ #endif