|
bool braceMatch(char pString[])//pString is input string
{
int Len;
char *p;
Stack myS;//myS is an object of class Stack
Len=strlen(pString);
p=pString;
while (*p!='\0')//string is not end
{
switch (*p)
{
case '(':
case '[':
case '{':
myS.Push(*p);
break;//the left bracket,push in stack
case ')':
if (myS.StackEmpty() || myS.Pop()!='(')
return false;
break;
case ']':
if (myS.StackEmpty() || myS.Pop()!='[')
return false;
break;
case '}':
if (myS.StackEmpty() || myS.Pop()!='{')
return false;
break;//check whether it matches
}
p++;
}
if (!myS.StackEmpty())
return false;
return true;
}
|