Exemplo n.º 1
0
 private void BuildStack(ref LIFO stack, string str)
 {
     if (IsNumber(str.ToString()) == true)
     {
         stack.Push(new Element(str));
     }
     else
     {
         stack.Push(MakeOperation(stack.Pop().Value, stack.Pop().Value, str.ToString()));
     }
 }
Exemplo n.º 2
0
        private double CalculateResult(string order)
        {
            LIFO stack = new LIFO();

            if (IsNumber(order[0].ToString()) == true)
            {
                for (int i = 0; i < order.Length; i++)
                {
                    BuildStack(ref stack, order[i].ToString());
                }
            }
            else
            {
                for (int i = order.Length - 1; i >= 0; i--)
                {
                    BuildStack(ref stack, order[i].ToString());
                }
            }

            return(Convert.ToDouble(stack.Pop().Value));
        }