选择排序

来源:互联网 发布:windows 7 x86 编辑:程序博客网 时间:2024/05/10 07:29
public class BubbleSort{     public static void main(String[] args){         int score[] = {67, 69, 100, 87, 89, 90, 75, 46};         System.out.print("排序前数组顺序:");         for(int a = 0; a < score.length; a++){             System.out.print(score[a] + "\t");         }         System.out.println("");         for (int i = 0; i < score.length; i++){    //最多做n-1趟排序             for(int j = i+1 ;j < score.length; j++){    //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键,这个范围是在逐步缩小的)                 if(score[i] > score[j]){                       int temp = score[i];                     score[i] = score[j];                     score[j] = temp;                 }             }                         System.out.print("第" + (i + 1) + "次排序结果:");             for(int a = 0; a < score.length; a++){                 System.out.print(score[a] + "\t");             }             System.out.println("");         }             System.out.print("最终排序结果:");             for(int a = 0; a < score.length; a++){                 System.out.print(score[a] + "\t");        }     } }