///主函数//Match.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#includeusingnamespacestd;#include#include#inclu...
///主函数
// Match.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
using namespace std;
#include
#include
#include "stack.h"
#include "error.h"
int _tmain(int argc, _TCHAR* argv[])
{
Stack p(MaxLength);
char expr[MaxLength];
cout<
cin.getline(expr,MaxLength);
cout<
puts(expr);
cout<
p.PrintMatchedPairs(expr);
return 0;
}
if(expr[i-1]=='['||expr[i-1]==']')
{
if(expr[i-1]=='[') s.Add(i); //左括号压栈
else if(expr[i-1]==']'&&s.Top( )=='[')//就是这里总出现问题try{s.Delete(j); //右括号弹栈
cout<
catch(OutOfBounds) //栈顶为空
{ cout<
else if(expr[i-1]==']'&&s.Top( )!='[')
cout<
}
if(expr[i-1]=='{'||expr[i-1]=='}')
{
if(expr[i-1]=='{') s.Add(i); //左括号压栈
else if(expr[i-1]=='}'&&s.Top( )=='{')
try{ s.Delete(j); //右括号弹栈
cout<
catch(OutOfBounds) //栈顶为空
{ cout<
else if(expr[i-1]=='}'&&s.Top( )!='{')
cout<
}
}
未匹配的(
while(!s.IsEmpty())
{
s.Delete(j);
cout<
}
}
展开