Не пойду почему не выводит отсортированный массив - C#
Формулировка задачи:
Листинг программы
- namespace ConsoleApplication3
- {
- public class Area
- {
- public static int[] InsertionSort(int[] a)
- {
- int p, b;
- for (int i = 1; i < a.Length; i++)
- {
- b = a[i];
- p = i - 1;
- while ((p >= 0) && (a[p] > b))
- {
- a[p + 1] = a[p];
- p--;
- }
- a[p + 1] = b;
- }
- return a;
- }
- public static int[] SelectionSort(int[] a)
- {
- int t;
- for (int i = 0; i < a.Length - 1; i++)
- {
- int min = i;
- for (int j = i + 1; j < a.Length; j++)
- {
- if (a[j] < a[min])
- min = j;
- }
- t = a[i];
- a[i] = a[min];
- a[min] = t;
- }
- return a;
- }
- public static int[] ShellSort(int[] a)
- {
- int n = a.Length;
- int t = 0;
- for (int d = n / 2; d > 0; d /= 2)
- {
- for (int i = d; i < n; i++)
- {
- t = a[i];
- for (int j = i; j >= d; j -= d)
- {
- if (t < a[j - d])
- a[j] = a[j - d];
- else
- break;
- a[j] = t;
- }
- }
- }
- return a;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите количество эл-в массива: ");
- int n = Convert.ToInt32(Console.ReadLine());
- int[] a = new int[n];
- Random r = new Random();
- for (int i = 0; i < a.Length; i++)
- {
- a[i] = r.Next(10);
- Console.Write(a[i] + "\t");
- }
- Console.WriteLine("Сортировка вставками: ", Area.InsertionSort(a));
- Console.WriteLine("Сортировка выбором: ", Area.SelectionSort(a));
- Console.WriteLine("Сортировка Шелла: ", Area.ShellSort(a));
- Console.ReadLine();
- }
- }
- }
Решение задачи: «Не пойду почему не выводит отсортированный массив»
textual
Листинг программы
- Console.WriteLine("Сортировка вставками: {0}", string.Join(", ", Area.InsertionSort(a)));
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д