Beispiel #1
0
        private static void Check(string input)
        {
            Delimiters <char> delimStack = new Delimiters <char>(10);

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input[i];
                switch (ch)
                {
                case '{':
                case '[':
                case '(':
                    delimStack.Push(ch);
                    break;

                case '}':
                case ']':
                case ')':
                    if (!delimStack.IsEmpty())
                    {
                        var cha = delimStack.Pop();
                        if ((ch == '}' && cha != '{') || (ch == ']' && cha != '[') || (ch == ')' && cha != '('))
                        {
                            Console.WriteLine($"Error: {ch} at {i}");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Error : {ch} at {i}");
                    }
                    break;

                default:
                    break;
                }
            }
            if (!delimStack.IsEmpty())
            {
                Console.WriteLine($"Missing right delimiter is {delimStack.Peek()}!");
            }
        }