一、冒泡排序
package test;
/**
* 测试冒泡排序
* @author 凡心所向,素履以往,生如逆旅,一苇一航
*
*/
public class maopao {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = {0,3,5,7,2,1,4,8,9,6};
int temp = 0;
for(int i=0;i<a.length-1;i++) {
for(int j=0;j<a.length-1-i;j++) {
if(a[j]>a[j+1]) {
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
//打印结果
for(int i = 0;i<a.length;i++) {
System.out.println(a[i]);
}
}
}
二、选择排序
选择排序:第一次从 R[0] ~ R[n-1] 中选取最小值,与 R[0] 进行交换,第二次从 R[1] ~ R[n-1] 中选择最小值与R[1]交换 .........,总共通过 n-1 次,得到一个安排序码从小到大的有序序码。