| 1 | /* $Id$Revision: */ |
| 2 | /* vim:set shiftwidth=4 ts=8: */ |
| 3 | |
| 4 | /********************************************************** |
| 5 | * See the LICENSE file for copyright information. * |
| 6 | **********************************************************/ |
| 7 | |
| 8 | #ifndef STACK_H |
| 9 | #define STACK_H |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | /* needed for intptr_t */ |
| 16 | #include "config.h" |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #include "misc.h" |
| 20 | |
| 21 | /* CONVENTIONS: All data structures for stacks have the prefix */ |
| 22 | /* "stk_" to prevent name conflicts. */ |
| 23 | /* */ |
| 24 | /* Function names: Each word in a function name begins with */ |
| 25 | /* a capital letter. An example funcntion name is */ |
| 26 | /* CreateRedTree(a,b,c). Furthermore, each function name */ |
| 27 | /* should begin with a capital letter to easily distinguish */ |
| 28 | /* them from variables. */ |
| 29 | /* */ |
| 30 | /* Variable names: Each word in a variable name begins with */ |
| 31 | /* a capital letter EXCEPT the first letter of the variable */ |
| 32 | /* name. For example, int newLongInt. Global variables have */ |
| 33 | /* names beginning with "g". An example of a global */ |
| 34 | /* variable name is gNewtonsConstant. */ |
| 35 | |
| 36 | /* if DATA_TYPE is undefined then stack.h and stack.c will be code for */ |
| 37 | /* stacks of void *, if they are defined then they will be stacks of the */ |
| 38 | /* appropriate data_type */ |
| 39 | |
| 40 | #ifndef DATA_TYPE |
| 41 | #define DATA_TYPE void * |
| 42 | #endif |
| 43 | |
| 44 | typedef struct stk_stack_node { |
| 45 | DATA_TYPE info; |
| 46 | struct stk_stack_node * next; |
| 47 | } stk_stack_node; |
| 48 | |
| 49 | typedef struct stk_stack { |
| 50 | stk_stack_node * top; |
| 51 | stk_stack_node * tail; |
| 52 | } stk_stack ; |
| 53 | |
| 54 | /* These functions are all very straightforward and self-commenting so */ |
| 55 | /* I didn't think additional comments would be useful */ |
| 56 | stk_stack * StackJoin(stk_stack * stack1, stk_stack * stack2); |
| 57 | stk_stack * StackCreate(void); |
| 58 | void StackPush(stk_stack * theStack, DATA_TYPE newInfoPointer); |
| 59 | void * StackPop(stk_stack * theStack); |
| 60 | intptr_t StackNotEmpty(stk_stack *); |
| 61 | |
| 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | #endif |
| 67 | |