public class TestDemo { public static void bubbleSort(int[] array){ for (int i = 0; i <array.length-1 ; i++) { boolean flg = false; for (int j = 0; j <array.length-1-i ; j++) { if(array[j]>array[j+1]){ int tmp = array[j]; array[j] = array[j+1]; array[j+1]= tmp; flg = true; } } if(flg = false){ return; } } } public static void main(String[] args) { int[] array = {12,1,23,15,16,13,17}; bubbleSort(array); System.out.println(Arrays.toString(array)); } }
Print results:
##Java sorting array function:Filling function: This function can be followed by three parameters: General The situation is all closed on the left and open on the right [2,6) form
The above is the detailed content of How to implement array sorting in java. For more information, please follow other related articles on the PHP Chinese website!