您的位置:首页 > 其它

排序算法四:选择排序

2015-10-25 22:48 323 查看
static void SelectionSort(int[] array)
{
for (int i = 0; i < array.Length-1; i++)
{
int maxIndex = i;
for(int j = i+1;j<array.Length;j++)
{
if(array[maxIndex] < array[j])
{
maxIndex = j;//找到最大值所在下标
}
}
int temp = array[i];
array[i] = array[maxIndex];
array[maxIndex] = temp;//交换i、maxIndex的值
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: