/*------------------------------------------------------------------*/ /* stack.h */ /* Author: Bob Dondero */ /* Interface of a generic stack ADT that uses function pointers */ /*------------------------------------------------------------------*/ #ifndef STACK_INCLUDED #define STACK_INCLUDED typedef struct Stack *Stack_T; /* A Stack_T is a last-in-first-out collection of items. */ Stack_T Stack_new(void); /* Return a new Stack_T. */ void Stack_free(Stack_T oStack); /* Free oStack. */ void Stack_push(Stack_T oStack, const void *pvItem); /* Push pvItem onto oStack. It is a checked runtime error for oStack to be NULL. */ void *Stack_pop(Stack_T oStack); /* Pop oStack, and return the popped item. It is a checked runtime error for oStack to be NULL or empty. */ int Stack_isEmpty(Stack_T oStack); /* Return 1 (TRUE) iff oStack is empty. It is a checked runtime error for oStack to be NULL. */ void Stack_map(Stack_T oStack, void (*pfApply)(void *pvItem, void *pvExtra), const void *pvExtra); /* Apply function *pfApply to each element of oStack, passing pvExtra as an extra argument. That is, for each element pvItem of oStack, call (*pfApply)(pvItem, pvExtra). It is a checked runtime error for oStack or pfApply to be NULL. */ #endif