typedef struct stack_mg{ unsigned int stack_count; // 栈的包含的数值 int struct stack_t *top; // 指向栈顶的位置 }Stack_mg_t;
//利用链表作为栈空间的节点数据结构,栈大小不受限 typedef struct stack_t { unsigned int value; // 栈的值 int struct stack_t *next; // 栈的下一个节点 }Stack_node;
/* PUSH 操作 */ void push_stack(Stack_mg_t *stack, int data) { if(NULL == stack) { return; } Stack_node *node = malloc(sizeof(Stack_node)); node->value = data; node->next = stack->top; stack->top = node; stack->stack_count++; }
/* POP 操作 */ void pop_stack(Stack_mg_t *stack) { if(NULL == stack||NULL == stack->top) { printf("Invalid\n"); return; } Stack_node *node = stack->top; printf("%ld\n", node->value); stack->top = stack->top->next; free(node); node = NULL; }
int main() { Stack_mg_t stack; memset(&stack,0,sizeof(Stack_mg_t));
}