/*-------------------------------------------------------------------*/ /* stack.h (Version 4: Abstract Data Types) */ /*-------------------------------------------------------------------*/ #ifndef STACK_INCLUDED #define STACK_INCLUDED struct Stack { double *pdArray; int iTop; int iMaxSize; }; extern struct Stack *Stack_new(int iMaxSize); /* Return the address of a new Stack that is able to store iMaxSize items, each of type double. */ extern void Stack_free(struct Stack *psStack); /* Free *psStack. */ extern void Stack_push(struct Stack *psStack, double dItem); /* Push dItem onto *psStack. */ extern double Stack_pop(struct Stack *psStack); /* Pop *psStack, and return the popped item. */ extern int Stack_empty(struct Stack *psStack); /* Return 1 (TRUE) iff *psStack is empty. */ extern int Stack_full(struct Stack *psStack); /* Return 1 (TRUE) iff *psStack is full. */ /* Checked runtime errors: Call any function with a NULL psStack. Call Stack_new with iMaxSize <= 0. Call Stack_push with *psStack full. Call Stack_pop with *psStack empty. */ #endif