Try to do a generic stack with C and throw it out to communicate with you.
#include <stdio.h>/** * Make a struct for stacks.
* I hope to make a generic struct of stacks.
* I may have a try. * * *//** Two variables: * 01.
Pointer to Char. * 02.
The position of the stack. * FROM 0 to MAX * 03.
The length of the array of char which is malloc.;
* * typedef struct STACK *STACKSP;
struct Stack {void *pt;
size_t top;
size_t length;
};
/** function judge whether stack is empty.
* Argument SP is a pointer to Stack.
* Should be aware this is equal to zero while the stack is empty.
* * #define SIZE_T ifempty (Stacksp sp) sp->top/** Push an element into the top of the stack. */#define PUSH (VarType, STACKSP, value) \ if (stacksp->top = = stacksp->length) fprintf (stderr, "Error:stack is full
.");\ ((VarType *) stacksp->pt)
[stacksp->top++] = value;
/** Pop () function return a element from the top of the stack.
* Warning:the element is also a pointer to void. * So your cannot referrence the variable by this pOinter, * you are to make some conventions. * * #define POPs (vartype, STACKSP) \ (stacksp->top = 0)?
NULL: ((VarType *) stacksp->pt) [--stacksp->top])/** free of the space applied. * * #define CLOSESTACK (VarType, Stacksp) if (stacksp->pt = = NULL) {\ free (VarType *) stacksp->pt); \ stacksp->top =
0;}
/** Malloc a space for stack. * **/#define OpenStack (vartype,stacksp,op_length) \ stacksp->pt = malloc (sizeof (vartype) * op_length); \ stacksp- >length = Op_length;
\ stacksp->top = 0;
Compile a few warning, obviously with C do generics or some irrational.