typedef struct {BiTree data[MaxSize];int top;
}SqStack;typedef struct {BiTree data[MaxSize];int front, rear;
}SqQueue;
void InitStack(SqStack& s) {s.top = -1;
}
bool StackIsEmpty(SqStack s) {if (s.top == -1)return false;elsereturn true;
}
bool push(SqStack& s, BiTree x) {if (s.top == MaxSize - 1) {return false; }s.data[++s.top] == x;return true;
}
bool pop(SqStack& s, BiTree& x) {if (s.top == -1) {return false;}x = s.data[s.top--];return true;
}
bool GetTop(SqStack s, BiTree& x) {if (s.top == -1)return false;x = s.data[s.top];return true;
}
void InitQueue(SqQueue& Q) {Q.front = Q.rear = 0;
}
bool QueueIsEmpty(SqQueue Q) {if (Q.rear == Q.front) return true;else return false;
}
bool EnQueue(SqQueue& Q, BiTree x) {if ((Q.front + 1) % MaxSize == Q.front) {return false;}Q.data[Q.rear] = x;Q.rear = (Q.rear + 1) % MaxSize;return true;
}
bool DeQueue(SqQueue& Q, BiTree x) {if (Q.rear == Q.front) {return false;}x = Q.data[Q.front];Q.front = (Q.front + 1) % MaxSize;return true;
}
typedef struct {int data[MaxSize];int top;
} SqStack;typedef struct {int data[MaxSize];int front, rear;int tag;
} SqQueue;
void InitStack(SqStack *S) {(*S).top = -1;
}
int StackIsEmpty(SqStack S) {if (S.top == -1) return 0;return 1;
}
int push(SqStack *S, int x) {if ((*S).top == MaxSize - 1) return 0;(*S).data[++(*S).top] = x;return 1;
}
int pop(SqStack *S, int *x) {if ((*S).top == -1) return 0;*x = (*S).data[(*S).top--];return 1;
}
void InitQueue(SqQueue *Q) {(*Q).rear = (*Q).front = 0;(*Q).tag = 0;
}
int QueueIsEmpty(SqQueue Q) {if (Q.rear == Q.front && Q.tag == 0) return 0;return 1;
}
int EnQueue(SqQueue *Q, int x) {if (Q->rear == Q->front && Q->tag == 1) return 0;(*Q).data[Q->rear] = x;Q->rear = (Q->rear + 1) % MaxSize;return 1;
}
int DeQueue(SqQueue *Q, int *x) {if (Q->rear == Q->front && Q->tag == 0) return 0;x = Q->data[Q->front];Q->front = (Q->front + 1) % MaxSize;return 1;
}
void Inversion(SqQueue *Q, SqStack *S) {int x;while (!QueueIsEmpty(*Q)) {DeQueue(Q, &x);push(S, x);}while (!StackIsEmpty(*S)) {pop(S, &x);EnQueue(Q, x);}
}
int Palindrome(char t[]) {int n = strlen(t);int i = 0;char c;SqStack S;while (i < n / 2) {push(&S, t[i]);i++;}if (n % 2 != 0)i++;while (!StackIsEmpty(S)) {pop(&S, c);if (c != t[i]) return 0;i++;}
}
int BracketCheck(char *str) {SqStack S;int i = 0;char c;while (str[i] != '\0') {switch (str[i]) {case '(':push(&S, '(');break;case '[':push(&S, '[');break;case '{':push(&S, '{');break;case ')':pop(&S, &c);if (c != '(') return 0;break;case ']':pop(&S, &c);if (c != '[') return 0;break;case '}':pop(&S, &c);if (c != '{') return 0;break;}i++;}if (!StackIsEmpty(S)) {printf("括号不匹配");return 0;} else {printf("括号匹配");return 1;};
}