我已经开始用c#创建快速排序算法。我了解quicksort算法的概念,但是当涉及到编码时,我完全迷失了,尤其是对编程还是陌生的。我选择了枢轴作为数组中的中间值,但我不知道如何将数组分为低和高
到目前为止的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quicksort
{
class Program
{
static void Main(string[] args)
{
int n = 11; //11 values in array to have 0-10 index
Random r = new Random();
int[] a; //index 0 to 10
a = new int[n];
a[0] = 0;
for (int i = 0; i < n; i++) //the array
a[i] = r.Next(1,100);
Console.WriteLine("The original array is: ");
for (int i = 0; i < n; i++)
{
Console.Write(a[i] + " ");
}
Console.WriteLine();
int pivot = a[n / 2];
Console.WriteLine("The pivot is:" + pivot);
Console.Read();
}
}
}