要求实现函数,借助如下自定义栈SqStack
判断一个中、小括符[
、]
、(
、)
组成的字符串中的括弧是否匹配,是则返回true
,否则返回false
。例如,[[()]]
、([[()]])
、(()[[]])
是匹配的,而(((
、()]
、 ([(]))
是不匹配的。
typedef char ElemType; // 为char取别名ElemType
struct SqStack{
ElemType *base; // 顺序栈的首地址,动态数组的首地址
int top; // 栈顶指针,栈非空时,为栈顶元素的下标(从0开始)
void Init( ); // 初始化栈
ElemType GetTop(); // 取栈顶元素
void Push(ElemType e); // 入栈
void Pop(); // 出栈
bool Empty(); // 判断空栈
};
函数接口定义:
bool matching(string exp);
其中参数 exp
是一个仅包含中、小括符[
、