Exemplo n.º 1
0
        private bool Match(string str)
        {
            SqStackClass st = new SqStackClass();
            int          i  = 0;
            string       x  = "";

            while (i < str.Length)
            {
                if (str[i] == '(')
                {
                    st.Push("(");
                }
                else if (str[i] == ')')
                {
                    if (!st.StackEmpty())
                    {
                        st.Pop(ref x);
                    }
                    else
                    {
                        return(false);
                    }
                }
                i++;
            }
            if (st.StackEmpty())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        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);
        }