Created
October 1, 2013 10:10
-
-
Save sdvcrx/6776339 to your computer and use it in GitHub Desktop.
平衡符号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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