数据结构之 栈的应用 括号匹配

int match(char a[],int n)
{
	char sq[maxSize];
	int top=-1;
	for(int i=0;i<n;i++)
	{
		if(a[i]=='(')
			sq[++top]=a[i];
		if(a[i]=='[')
			sq[++top]=a[i];
		if(a[i]==')')
		{
			if(top==-1)
				return 0;
			if(sq[top]=='(')
				--top;
		}
		if(a[i]==']')
		{
			if(top==-1)
				return 0;
			if(sq[top]=='[')
				--top;
		}
	}
	if(top==-1)
		return 1;
	else
		return 0;
}

原文地址:https://www.cnblogs.com/zhujunxxxxx/p/3348806.html