Ejemplo 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;
            }
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     try
     {
         JStack nums       = new JStack();
         JStack ops        = new JStack(); // Need to add user input option
         string expression = "5 + 10 + 15 + 20";
         Calculate(nums, ops, expression);
         Console.WriteLine(nums.Pop());
         Console.ReadLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine("Invalid Input");
         Console.ReadLine();
     }
 }
Ejemplo 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);
        }