📄 test.cpp
字号:
#include"Stack.h"
#include<iostream>
#include<xstring>
#include<string>
//利用栈进行括号匹配
using namespace std;
void main()
{
SqStack s;
ElementType e;
int n;
string line;
InitSqStack(s);
getline(cin,line);
for(n=0;n<line.length ();n++)
{if(!IsSqStackEmpty(s))
switch(GetSqStackTop(s,e),e)
{
case '[':{
if(line[n]==']')
Pop(s,e);
else if(line[n]=='[')
Push(s,line[n]);
}
break;
/* case '(':{
if(line[n]==')')
Pop(s,e);
else
Push(s,line[n]);
}
case default:Push(s,line[n]);
*/ }
else
if(line[n]=='[')
Push(s,line[n]);
else if(line[n]==']') cout<<"Not"<<endl;
}
if(IsSqStackEmpty(s))
cout<<"匹配成功"<<endl;
else
cout<<"匹配不成功"<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -