帮下忙!
谁能告诉我主函数里要怎么用sort函数?sort(?,?,?)
下面是快速排序算法程序:
class Program
{
private void swap(ref int l, ref int r)
{
int temp;
temp = l;
l = r;
r = temp;
}
public void sort(int[] list, int low, int high)
{
int pivot;//存储分支点
int l, r;
int mid;
if (high <= low)
return;
else if (high == low + 1)
{
if (list[low] > list[high])
swap(ref list[low], ref list[high]);
return;
}
mid = (low + high) >> 1;
pivot = list[mid];
swap(ref list[low], ref list[mid]);
l = low + 1;
r = high;
do
{
while (1 <= r && list[l] < pivot)
l++;
while (list[r] >= pivot)
r--;
if (l < r)
swap(ref list[l], ref list[r]);
} while (l < r);
list[low] = list[r];
list[r] = pivot;
if (low + 1 < r)
sort(list, low, r - 1);
if (r + 1 < high)
sort(list, r + 1, high);
}
static void Main(string[] args)
{
int[] list = { 1, 5, 6, 8, 45, 68, 27, 78, 68, 248, 57, 11 };
Console.ReadKey();
}
}
}
浙公网安备 33010602011771号