///
/// 快速排序法
///
///
///
///
public static void Sort(ref int[] data, int start, int end)
{
if (start >= end) return;
if (start + 1 == end)
{
if (data[start] > data[end])
Swap(ref data, start, end);
return;
}
int indexL = start + 1, indexR = end;
while (indexL < indexR)
{
// Get from left
while (indexL <= end && data[start] >= data[indexL])
indexL++;
// Get from right
while (indexR > start && data[start] < data[indexR])
indexR--;
if (indexL < indexR)
{
Swap(ref data, indexR, indexL);
}
}
if (indexL - 1 != start)
Swap(ref data, start, indexL - 1);
Sort(ref data, start, indexL - 2);
Sort(ref data, indexL, end);
}
int k;
int[] array = new int[10] { 100,5,6,87,26,33,77,99,10,88};
for (int i = 0; i < 10; i++)
{
for (int j = i; j < 10; j++)
{
if (array[i] < array[j])
{
k = array[i];
array[i] = array[j];
array[j] = k;
}
}
}
for(int i = 0; i < 10;i++)
Console.Write(array[i]+"\t");
Console.ReadLine();
冒泡,很简单