本文介绍了我想要一种有效的排序算法来对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for (int i = 1; i < data.Count; i++)
{
int j = i;
while (j > 0)
{
if (numarray[j - 1] > numarray[j])
{
int temp = numarray[j - 1];
numarray[j - 1] = numarray[j];
numarray[j] = temp;
j--;
}
else
break;
}
}
有人可以帮助我识别上述代码的排序算法吗?我知道气泡排序不是很有效.如果我要改用插入排序算法,则如何改进上面的代码.谢谢!
Can someone help me identify what is the sorting algorithm of the above code? I know that bubble sort is not very efficient. If I am to use insertion sort algorithm instead, how can I improve the above code. Thankyou!
推荐答案
只需执行以下操作:
Array.Sort(data);
这篇关于我想要一种有效的排序算法来对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!