CharMatch(括号匹配)

用自己定义的链栈实现括号匹配

 1 #include"LinkStack.h"
 2 bool Match(char *s)
 3 {
 4     LinkStack<char> tmpS;
 5     char tmpCh;
 6     for(int i=0;i<strlen(s);i++)
 7     {
 8         if(s[i]=='('||s[i]=='['||s[i]=='{')
 9             tmpS.Push(s[i]);
10         else if(s[i]==')')
11         {
12             if(tmpS.Empty())
13                 return false;
14             else if(tmpS.Top(tmpCh),tmpCh=='(')
15                 tmpS.Pop(tmpCh);
16             else 
17                 return false;
18         }
19         else if(s[i]==']')
20         {
21             if(tmpS.Empty())
22                 return false;
23             else if(tmpS.Top(tmpCh),tmpCh=='[')
24                 tmpS.Pop(tmpCh);
25             else 
26                 return false;
27         }
28         else if(s[i]=='}')
29         {
30             if(tmpS.Empty())
31                 return false;
32             else if(tmpS.Top(tmpCh),tmpCh=='{')
33                 tmpS.Pop(tmpCh);
34             else 
35                 return false;
36         }
37     }
38     if(tmpS.Empty())
39         return true;    
40     else 
41         return false;    
42 }
bool Match(char *s)
原文地址:https://www.cnblogs.com/ljwTiey/p/4268121.html