예제 #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);
            }
        }
예제 #2
0
        private void OutBtn_Click(object sender, EventArgs e)
        {
            string x = "";
            int    k;

            if (OutBtn.Text == "出顺序栈")
            {
                if (sq.Pop(ref x))
                {
                    textBox3.Text = x;
                    Display1();
                    infolabel.Text = "出栈成功";
                    label3.Text    = "出栈元素";
                }
            }

            if (OutBtn.Text == "出链栈")
            {
                if (li.Pop(ref x))
                {
                    textBox3.Text = x;
                    Display3();
                    infolabel.Text = "出栈成功";
                    label3.Text    = "出栈元素";
                }
            }

            if (OutBtn.Text == "出队")
            {
                if (textBox3.Text == "")
                {
                    if (qu.deQueue(ref x))
                    {
                        textBox4.Text = x;
                        Display2();
                        infolabel.Text = "出队成功";
                    }
                }
                else
                {
                    k = Convert.ToInt16(textBox3.Text.Trim());
                    if (deQueue(k, ref x))
                    {
                        textBox4.Text = x;
                        Display2();
                        infolabel.Text = "出队成功";
                    }
                }
            }
        }
예제 #3
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);
        }