#include "stack.h" int main(void) { ElemType ch; Stack s; ElemType pop, top; bool flag = true; InitStack(&s); while ((ch = getchar()) != '\n' && flag) { switch (ch) { case '(': Push(&s,ch); break; case '[': Push(&s,ch); break; case ')': if (StackIsEmpty(&s) || (top = GetTop(&s)) != '(') flag = false; else if (top == '(') Pop(&s,&pop); break; case ']': if (StackIsEmpty(&s) || (top = GetTop(&s)) != '[') flag = false; else if (top == '[') Pop(&s,&pop); break; } } if (StackIsEmpty(&s) && flag) printf("Matching successful!\n\n"); else { fprintf(stderr,"Matching failed!\n\n"); DestroyStack(&s); } return 0; }