1.动态链表的初始化:
typedef struct _STACK{
void* data;
int size;
struct _STACK* next;
struct _STACK* pre;
} STACK;
STACK *stack;
STACK *_stack;
void initStack()
{
stack = (STACK*)malloc(sizeof(STACK));
stack->data = (DATA*)malloc(sizeof(DATA));
stack->size = sizeof(DATA);
stack->next = NULL;
stack->pre = NULL;
_stack = NULL;
}
2.创建和内存申请:
void creatStack()
{
if(_stack == NULL) {
_stack = stack;
}else {
STACK* pStack = (STACK*)malloc(sizeof(STACK));
pStack->data = (DATA*)malloc(sizeof(DATA));
pStack->size = sizeof(STACK);
pStack->next = NULL;
_stack->next = pStack;
pStack->pre = _stack;
_stack = _stack->next;
}
}
3.释放内存
void releaseStack()
{
DATA* data;
while(NULL != stack)
{
STACK* sta = stack;
stack = stack->next;
data = (DATA*)sta->data;
if(data->type == Array)
free(data->t.a.valp);
free(sta->data);
free(sta);
}
}