Example #1
0
        public T Dequeue()
        {
            if (s2.IsEmpty())
            {
                if (s1.IsEmpty())
                {
                    throw new InvalidOperationException("No elements in Queue");
                }

                while (!s1.IsEmpty())
                {
                    s2.Push(s1.Pop());
                }
            }
            return(s2.Pop());
        }
Example #2
0
        public static bool CheckMachingBracket(string input)
        {
            GenericStack <char> stack = new GenericStack <char>();

            for (int i = 0; i < input.Length; i++)
            {
                char current = input[i];
                if (current == '[' || current == '{' || current == '(')
                {
                    stack.Push(current);
                }
                else if (current == ']' || current == '}' || current == ')')
                {
                    if (stack.IsEmpty())
                    {
                        return(false);
                    }
                    char x = stack.Pop();
                    if ((x == '(' && current != ')') || (x == '[' && current != ']') || (x == '{' && current != '}'))
                    {
                        return(false);
                    }
                }
            }
            if (stack.IsEmpty())
            {
                return(true);
            }

            return(false);
        }
Example #3
0
 public void Enqueue(T element)
 {
     s1.Push(element);
 }