Files
2025-07-26 22:44:47 +03:00

27 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Задача 4.1 - сумма массива в виде рекурсивной функции
int[] arr = [1, 2, 3];
Console.WriteLine($"4.1. Сумма: [{string.Join(", ", arr)}] равна {Task4_1.Calculate(arr)}");
// Задача 4.2 - количество элементов в списке в виде рекурсивной функции
LinkedList<int> list = new LinkedList<int>([10, 20, 30, 40, 50]);
Console.WriteLine($"4.2. Количество элементов в списке: {Task4_2.Count(list.First!)}");
// Задача 4.3 - поиск максимального элемента в LinkedList с помощью рекурсии
// Пример: находим максимум в списке [7, 2, 9, 4, 5]
LinkedList<int> list2 = new LinkedList<int>([7, 2, 9, 4, 5]);
Console.WriteLine($"4.3. Максимум в списке: {Task4_3.Max(list2.First!)}");
// Задача 4.4 - бинарный поиск в отсортированной коллекции с помощью рекурсии
int[] sortedArr = [10, 20, 30, 40, 50, 60];
int target = 42;
int index = Task4_4.BinSearch(sortedArr, target, 0, sortedArr.Length - 1);
Console.WriteLine($"4.4. Индекс числа {target} в массиве: {index}");
// Пример использования QuickSort
List<int> unsorted = new() { 5, 2, 9, 1, 7, 3 };
Console.WriteLine("Быстрая сортировка");
Console.WriteLine($"Неотсортированный список: {string.Join(", ", unsorted)}");
var sorted = QuickSort.Sort(unsorted, Comparer<int>.Default);
Console.WriteLine($"Отсортированный список: {string.Join(", ", sorted)}");