idk why these stuffs get stashed for so long and I didn't ever commit them

This commit is contained in:
2025-11-06 09:43:54 +08:00
parent 5dbdfef1a1
commit e01c041259
232 changed files with 22806 additions and 1256 deletions

View File

@@ -0,0 +1,54 @@
#include <string>
#include <iostream>
using namespace std;
#include "LinkStack.h"
bool match(string exp)
{
SNode<char>* S;
InitStack(S);
int flag = 1, i = 0;
char ch, e, x;
ch = exp[i++];
while (ch != '#' && flag)
{
switch (ch)
{
case '[':
case '(':
cout << "左括号进栈!" << endl;
Push(S, ch);
break;
case ')':
GetTop(S, e);
if (!StackEmpty(S) && e == '(')
{
Pop(S, x);
cout << "右括号出栈!" << endl;
}
else flag = 0;
break;
case ']':
GetTop(S, e);
if (!StackEmpty(S) && e == '[') Pop(S, x);
else flag = 0;
break;
}
ch = exp[i++];
}
if (StackEmpty(S) && flag) return true;
else return false;
}
int main()
{
int flag;
string exp;
cout << "请输入待匹配的表达式,以“#”结束:" << endl;
cin >> exp;
flag = match(exp);
if (flag) cout << "括号匹配成功!" << endl;
else cout << "括号匹配失败!" << endl;
return 0;
}