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

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;
}

posted @ 2013-09-28 23:54  小竹zz  阅读(133)  评论(0编辑  收藏  举报