Исправить код и вывод сортировки - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n = 10;
int[] a = new int[n];
Random rand = new Random();
for (int i = 0; i < n; i++)
{
a[i] = rand.Next(100);
}
Console.ReadKey();
}
private static int[] QuickSort(int[] a, int i, int j)
{
if (i < j)
{
int q = Partition(a, i, j);
a = QuickSort(a, i, q);
a = QuickSort(a, q + 1, j);
}
return a;
}
private static int Partition(int[] a, int p, int r)
{
int x = a[p];
int i = p - 1;
int j = r + 1;
while (true)
{
do
{
j--;
}
while (a[j] > x);
do
{
i++;
}
while (a[i] < x);
if (i < j)
{
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
else
{
return j;
}
}
}
}
}Решение задачи: «Исправить код и вывод сортировки»
textual
Листинг программы
static void Main(string[] args)
{
int n = 10;
int[] a = new int[n];
Random rand = new Random();
for (int i = 0; i < n; i++)
{
a[i] = rand.Next(100);
Console.WriteLine(a[i]);
}
Console.ReadKey();
}