Java 冒泡排序
概要:
Java 冒泡排序
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | packagenet.xsoftlab.baike;/** * @desc 冒泡排序实现 */publicclassSort {    privateint[] num = { 4, 3, 2, 1, 5};    publicvoidsort() {        inttmp = 0;        for(inti = num.length - 1; i > 0; i--) {            for(intj = 0; j < i; j++) {                if(num[j] > num[j + 1]) {                    tmp = num[j + 1];                    num[j + 1] = num[j];                    num[j] = tmp;                }            }        }    }    publicvoidprint() {        for(inti : num) {            System.out.println(i);        }    }    publicstaticvoidmain(String args[]) {        Sort t = newSort();        t.sort();        t.print();    }}
 | 
 
                    
                 
                
            
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号