Example #1
0
        private static void ConsoleWriteTree(SegmentTree tree)
        {
            int index = 0;

            foreach (var x in tree)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write($"{x}");
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write($"[{index++}] ");
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            Console.WriteLine();
            Console.WriteLine();
        }
Example #2
0
 //TEST
 private static void MinInRangeTest(SegmentTree IntTree)
 {
     GetRange(out int minIndex, out int maxIndex);
     try
     {
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine($"Минимум на отрезке [{minIndex - 1},{maxIndex - 1}] - {IntTree.FindMinBetween(minIndex, maxIndex)}");
     }
     catch (IndexOutOfRangeException e)
     {
         Notification(e.Message);
     }
     finally
     {
         Console.ForegroundColor = ConsoleColor.Gray;
     }
     Console.WriteLine();
 }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Дерево отрезков - структура полезна когда необходимо часто искать значение какой-то функции на отрезках линейного массива и иметь возможность быстро изменять значения группы подряд идущих элементов.");
            Console.WriteLine();

            SegmentTree IntTree = GetSeries();

            ConsoleWriteTree(IntTree);

            Console.WriteLine();
            Console.WriteLine("Быстрая функция - минимум на отрезке");
            MinInRangeTest(IntTree);

            Console.WriteLine("Проверка возможности быстро изменить значение");
            ChangeInIndext(IntTree);
            ConsoleWriteTree(IntTree);

            Console.WriteLine("Быстрая функция - минимум на отрезке");
            MinInRangeTest(IntTree);

            Console.ReadLine();
        }
Example #4
0
 private static void ChangeInIndext(SegmentTree IntTree)
 {
     GetUpdate(out int indexToUpdate, out int valToUpdate);
     IntTree[indexToUpdate] = valToUpdate;
 }