Exemplo n.º 1
0
        static void Compute(JStack N, JStack O)
        {
            int    operand1;
            int    operand2;
            string oper;

            operand1 = Convert.ToInt32(N.Pop());
            operand2 = Convert.ToInt32(N.Pop());
            oper     = Convert.ToString(O.Pop());
            switch (oper)
            {
            case "+":
                N.Push(operand1 + operand2);
                break;

            case "-":
                N.Push(operand1 - operand2);
                break;

            case "*":
                N.Push(operand1 * operand2);
                break;

            case "/":
                N.Push(operand1 / operand2);
                break;
            }
        }
Exemplo n.º 2
0
        static void Calculate(JStack N, JStack O, string exp)
        {
            string ch;
            string token = string.Empty;

            for (int p = 0; p < exp.Length; p++)
            {
                ch = exp.Substring(p, 1);
                if (IsNumeric(ch) == true)
                {
                    token += ch;
                }
                if (ch == " " || p == (exp.Length - 1))
                {
                    if (IsNumeric(token))
                    {
                        N.Push(token);
                        token = string.Empty;
                    }
                }
                else if (ch == "+" || ch == "-" || ch == "*" || ch == "/")
                {
                    O.Push(ch);
                }
                if (N.Count == 2)
                {
                    Compute(N, O);
                }
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            var testing = new JStack<int>();

            testing.Push(1);
            testing.Push(2);
            Console.WriteLine(testing.Peek());
            Console.WriteLine(testing.Pop());
            Console.WriteLine(testing.Count);
            Console.WriteLine(testing.Peek());
            Console.WriteLine(testing.Count);
            testing.Push(1);
            testing.Push(2);
            testing.Push(1);
            testing.Push(2);
            testing.Push(1);
            testing.Push(2);
            Console.WriteLine(testing.Count);
        }