import java.util.Scanner; |
public class code1 { |
public static void main(String[] args) { |
int a[]= new int [ 10 ]; |
int temp; |
Scanner in = new Scanner(System.in); |
for ( int i= 1 ;i<=a.length;i++){ |
System.out.println( "请输入第" +i+ "个数的值" ); |
a[i- 1 ]=in.nextInt(); |
} |
/*for (int i = 0; i < a.length - 1; i++) { |
for (int j = 0; j < a.length-1; j++) { |
if (a[j] > a[j + 1]) { |
temp = a[j + 1]; |
a[j + 1] = a[j]; |
a[j] = temp; |
} |
} |
}*/ |
for ( int i = 0 ; i < a.length - 1 ; 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 i= 0 ;i<a.length;i++){ |
System.out.println(a[i]); |
} |
} |
} |
冒泡排序思考一轮排序几次,一共排序几轮。 |
选择排序要先选定一个比较的位置,与其余的位置进行比较,选出最大的或是最小的,然后第二个位置与剔除第一次选择位置之后剩余的位置进行比较,比较次数越来越少,计算量小。 |