如下的代码内容是关于C#堆排序的代码。
private static void Adjust (int[] list, int i, int m)
{
int Temp = list[i];
while (j <= m)
{
if(j < m)
if(list[j] < list[j + 1])
j = j + 1;
if(Temp < list[j])
{
list[i] = list[j];
i = j;
}
else
{
j = m + 1;
}
}
list [i] = Temp;
}
public static void HeapSort (int[] list)
{
for (int i = (list.Length - 1) / 2; i > = 0; i-)
Adjust (list, i, list.Length - 1);
for (int i = list.Length - 1; i > = 1; i-)
{
int Temp = list [0];
list [0] = list [i];
list [i] = Temp;
Adjust (list, 0, i - 1);
}
}
网友评论