Esempio n. 1
0
 private float Counting(string input)
 {
     for (int i = 0; i < input.Length; i++)
     {
         if (Char.IsDigit(input[i]))
         {
             string a = "";
             while (!IsGap(input[i]) && !IsOperator(input[i]))
             {
                 a += input[i];
                 i++;
                 if (i == input.Length)
                 {
                     break;
                 }
             }
             quantityStack.Push(float.Parse(a));
             i--;
         }
         else if (IsOperator(input[i]))
         {
             float a = quantityStack.Pop();
             float b = quantityStack.Pop();
             quantityStack.Push(CalculateOperation(input, i, a, b));
         }
     }
     return(quantityStack.Peek());
 }
Esempio n. 2
0
        private string GetExpression(string input)
        {
            string output = "";

            for (int i = 0; i < input.Length; i++)
            {
                if (IsGap(input[i]))
                {
                    continue;
                }

                if (IsQuantity(input, i))
                {
                    while (!IsGap(input[i]) && !IsOperator(input[i]))
                    {
                        output += input[i];
                        i++;
                        if (i == input.Length)
                        {
                            break;
                        }
                    }
                    output += " ";
                    i--;
                }

                if (IsOperator(input[i]))
                {
                    if (input[i] == '(')
                    {
                        operatorsStack.Push(input[i]);
                    }
                    else if (input[i] == ')')
                    {
                        char s = operatorsStack.Pop();
                        while (s != '(')
                        {
                            output += s.ToString() + ' ';
                            s       = operatorsStack.Pop();
                        }
                    }
                    else
                    {
                        if (operatorsStack.Count > 0 && GetPriority(input[i]) <= GetPriority(operatorsStack.Peek()))
                        {
                            output += operatorsStack.Pop().ToString() + " ";
                        }
                        operatorsStack.Push(char.Parse(input[i].ToString()));
                    }
                }
            }
            while (operatorsStack.Count > 0)
            {
                output += operatorsStack.Pop() + " ";
            }
            return(output);
        }
Esempio n. 3
0
 private static void AddColorInIceCream(LinkedStack <ColorPalette> iceCream, ColorPalette color)
 {
     iceCream.Push(color);
     Console.WriteLine($"Мороженное цвета {color.color}");
 }