private bool Match(string str) //括号匹配 { int j; string x = ""; SqStackClass st = new SqStackClass(); for (j = 0; j < str.Length; j++) { if (str[j] == '(') { st.Push("("); } else if (str[j] == ')') { if (!st.StrackEmpty()) { st.Pop(ref x); } else { return(false); } } } if (st.StrackEmpty()) { return(true); } else { return(false); } }
private bool Palindrome(string str) //回文判断 { int i; string x = ""; SqStackClass st = new SqStackClass(); for (i = 0; i < str.Length; i++) { x = str[i].ToString(); st.Push(x); } for (i = 0; i < str.Length; i++) { st.Pop(ref x); if (string.Compare(str[i].ToString(), x) != 0) { return(false); } } return(true); }