#define DEFINE_STACK_NODE(type, name) \
struct name##_node{ \
type data; \
name##_node * prior; \
};
#define DEFINE_STACK(type , name ) \
DEFINE_STACK_NODE(type, name) \
struct name##stack{ \
int size; \
struct name##_node * base; \
struct name##_node * top; \
}name##_stack; \
#define init(name) \
do{ \
name##_stack.base = name##_stack.top=(name##_node *)0; \
name##_stack.size=0; \
}while(0)
#define top(name,elem) \
do{ \
if(name##_stack.size){ \
*elem = name##_stack.top->data;\
}while(0)
#define push(name, elem) \
do{ \
name##_node * temp =(name##_node *)malloc(sizeof(name##_node)); \
temp->data=elem; \
++(name##_stack.size); \
if(1!=name##_stack.size) { \
temp->prior = name##_stack.top; \
name##_stack.top=temp; \
}else{ \
temp->prior =(name##_node *)0; \
name##_stack.top=name##_stack.base = temp; \
} \
}while(0)
#define pop(name, elem) \
do{\
name##_node * temp=name##_stack.top;\
if(name##_stack.size){ \
*elem = name##_stack.top->data; \
if(1!=name##_stack.size--){\
name##_stack.top = temp->prior;\
}else{\
name##_stack.top=name##_stack.base=(name##_node *)0; \
}\
free(temp);\
}\
}while(0)
#define clear(name) \
do{\
for(;name##_stack.size; --name##_stack.size){\
name##_node * temp = name##_stack.top;\
name##_stack.top=name##_stack.top->prior;\
free(temp);\
}\
}while(0)
#define length(name) name##_stack.size
#define empty(name) (!name##_stack.size)?1:0