public static bool isExpressionValid(char[] array)
        {
            StackOperations stack = new StackOperations(array.Length);

            foreach (var item in array)
            {
                if (item == '{' || item == '[' || item == '(')
                {
                    stack.Push(item);
                }
                else
                {
                    if (stack.IsEmpty())
                    {
                        return(false);
                    }
                    if (!isParenthesesMatching(Convert.ToChar(stack.Pop()), item))
                    {
                        return(false);
                    }
                }
            }
            if (stack.IsEmpty())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 public void Push(int x)
 {
     if (stack.IsEmpty())
     {
         minElement = x;
         stack.Push(x);
     }
     else if (x < minElement)
     {
         minElement = x;
     }
     else
     {
         stack.Push(x);
     }
 }