Ejemplo n.º 1
0
        static void Task5(String str)
        {
            MyDeque <char> Deque3 = new MyDeque <char>(str.Length + 1);

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '[')
                {
                    Deque3.PushBack('[');
                }
                else if (str[i] == ']')
                {
                    if (Deque3.Count == 0)
                    {
                        Console.WriteLine("Количество '[' не равно количеству скобок ']'");
                        return;
                    }
                    Deque3.PopBack();
                }
            }

            if (Deque3.Count == 0)
            {
                Console.WriteLine("Количество '[' равно количеству скобок ']'");
            }
            else
            {
                Console.WriteLine("Количество '[' не равно количеству скобок ']'");
            }
        }
Ejemplo n.º 2
0
        //заполняем дек числами отрицательными и положительными, переворачиваем и выводим
        static void Task7(int[] arr)
        {
            MyDeque <int> Dec4 = new MyDeque <int>(arr.Length + 1);

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] < 0)
                {
                    Dec4.PushFront(arr[i]);
                }
                else
                {
                    Dec4.PushBack(arr[i]);
                }
            }

            for (int i = 1; i < arr.Length; i++)
            {
                int x = Dec4.PopFront();
                if (x < 0)
                {
                    Dec4.PushBack(x);
                }
                else
                {
                    Dec4.PushFront(x);
                    break;
                }
            }

            while (true)
            {
                int x = Dec4.PopBack();
                if (x < 0)
                {
                    Console.Write(x + " ");
                }
                else
                {
                    Dec4.PushBack(x);
                    break;
                }
            }

            while (Dec4.Count > 0)
            {
                Console.Write(Dec4.PopFront() + " ");
            }
        }
Ejemplo n.º 3
0
        static void Task55(String str)
        {
            MyDeque <char> Deque3 = new MyDeque <char>(str.Length + 1);

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '[')
                {
                    Deque3.PushFront('[');
                }
                else if (str[i] == ']')
                {
                    Deque3.PushBack(']');
                }
            }

            int count = 0;

            while (true)
            {
                char ch = Deque3.PopFront();
                if (ch == '[')
                {
                    count++;
                }
                else
                {
                    break;
                }
            }

            if (count == str.Length - count)
            {
                Console.WriteLine("Количество '[' равно количеству скобок ']'");
            }
            else
            {
                Console.WriteLine("Количество '[' не равно количеству скобок ']'");
            }
        }
Ejemplo n.º 4
0
        //заполняем первый стек, что меньше то влево, что больше то вправо
        //если необходимо вставить элемент то в цикле вытаскиваем все элементы, вставляем и возвращаем остальные

        static void Task1(List <String> books)
        {
            MyDeque <String> q1 = new MyDeque <string>(books.Count + 1);
            MyDeque <String> q2 = new MyDeque <string>(books.Count + 1);

            for (int i = 0; i < books.Count; i++)
            {
                if (q1.Count == 0)
                {
                    q1.PushBack(books[i]);
                }
                else if (String.Compare(books[i], q1.PeekBack()) == 1)
                {
                    q1.PushBack(books[i]);
                }
                else if (String.Compare(books[i], q1.PeekFront()) == -1)
                {
                    q1.PushFront(books[i]);
                }
                else
                {
                    while (String.Compare(books[i], q1.PeekFront()) == 1)
                    {
                        q2.PushBack(q1.PopFront());
                    }

                    q1.PushFront(books[i]);

                    while (q2.Count != 0)
                    {
                        q1.PushFront(q2.PopBack());
                    }
                }
            }
            q1.PrintDec();
        }