这是什么排序算法的名称?
问题描述:
for(int i=0; i<n-1; i++)
{
for(int j=i+1; j<n; j++)
{
if(a[i] > a[j])
{
/* Swap a[i] and a[j] */
}
}
}
PS 给定一个算法的名称,人们可以很容易地找到相应和源$ C $ C。但是,我觉得很难做到,反之亦然:D
P.S. Given the name of an algorithm, one can easily find relevent source code. But I find it hard to do the vice-versa :D
修改哦!如果是冒泡排序,那么什么是这个名字:
Edit Oh! If that is bubble sort, then what is the name of this:
for(int i=0; i<n; i++)
{
for(int j=0; j<n-1; j++)
{
if(a[j] > a[j+1])
{
/* Swap a[j] and a[j+1] */
}
}
}
我认为这第二个泡沫的更小的元素,所以我想的这个的竟是冒泡排序。如果第一个是冒泡排序,有什么的第二个名字?
I thought this second one "bubbles" the smaller elements up, so I thought this was actually bubble sort. If the first one is bubble sort, what's the name of the second one?
答
首先是选择排序,你添加第二个是冒泡排序!
First is the Selection Sort and the second one you added is Bubble sort!