#include #include typedef struct LinkStack { char data; struct LinkStack *next; } LinkStack; LinkStack *push(LinkStack *top, char a) { LinkStack *line = (LinkStack *) malloc(sizeof(LinkStack)); line->data = a; line->next = top; top = line; return top; } LinkStack *pop(LinkStack *top) { if (top) { LinkStack *p = top; top = top->next; printf("old top = %c; ", p->data); if (top) { printf("new top = %c\n", top->data); } else { printf("empty\n"); } free(p); } else { printf("Stack Empty\n"); return top; } return top; } int stackEmpty(LinkStack *top) { if (top == NULL) { return 1; //链栈为空 } else { return 0; // 链栈不为空 } } char getTop(LinkStack* top) { if (stackEmpty(top)) { printf("stack empty"); exit(0); } else { return top->data; } }