#include <stdio.h>
#include <string>
#include <iostream>
#include "stack.hpp"
int main()
{
Stack<int> stack;
int op = 0;
while (1)
op = 0;
printf("选择操作:1入栈2出栈3深度4是否空5栈顶6退出\n");
scanf("%d", &op);
switch (op)
case 1:
printf("输入\n");
stack.push(op);
break;
case 2:
printf("出%d \n", stack.pop());
case 3:
printf("深度%d \n", stack.depth());
case 4:
printf("%d \n", stack.empty());
case 5:
printf("%d \n", stack.top());
case 6:
goto Out;
default:
}
Out:
Stack<char> S;
std::string exp;
bool flag = true;
printf("输入算式\n");
std::cin >> exp;
for (int i = 0; i < sizeof(exp); i++)
switch (exp[i])
case '(':
case '[':
case '{':
S.push(exp[i]);
case ')':
'(' != S.pop() ? flag = false : 0;
case ']':
'[' != S.pop() ? flag = false : 0;
case '}':
'{' != S.pop() ? flag = false : 0;
(flag==true&&S.empty()) ? printf("匹配成功\n") : printf("匹配失败\n");