Skip to content

Instantly share code, notes, and snippets.

@sdvcrx
Created October 1, 2013 10:10
Show Gist options
  • Save sdvcrx/6776339 to your computer and use it in GitHub Desktop.
Save sdvcrx/6776339 to your computer and use it in GitHub Desktop.
平衡符号
int checkSymbol(Stack S){
char ch;
while((ch = getchar()) != '#'){
if(ch == '(' || ch == '[' || ch == '{'){
Push(ch, S);
}
else if(ch == ')' || ch == ']' || ch == '}'){
if(isEmpty(S))
Error("Stack is empty");
else{
switch(ch){
case ')':
if(Top(S) != '(')
Error("not match");
else
break;
case ']':
if(Top(S) != '[')
Error("not match");
else
break;
case '}':
if(Top(S) != '{')
Error("not match");
else
break;
}
Pop(S);
}
}
}
if(!IsEmpty(S))
Error("the stack is not empty last");
else
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment