您的位置:首页 > 其它

选择排序

2015-06-27 14:26 246 查看
/**
* Created by xuxiaoyu on 2015/6/25.
*/
//选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换,
//第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1趟遍历剩下的2个数据,
//找出其中最小的数值与第N-1个元素交换,至此选择排序完成
public class SelectionSort {

public static void main(String[] args) {
int a[] = { 2, 5, 8, 3, 2, 9, 7, 6, 1, 4,3333,22 };
int temp;
for (int i = 0; i < a.length; i++)
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
for (int k = 0; k < a.length; k++)
System.out.print(a[k] + "、");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: