public static void main(String[] args) { int[] arr = {6,5,3,54,3,3,6,58}; int[] out = sort(arr); System.out.println(Arrays.toString(out)); } public static int[] sort(int[] test){ int temp = 0; for (int i = 0; i < test.length-1; i++) { boolean flag = false; for (int j = 0; j < test.length-1-i; j++) { if (test[j]>test[j+1]) { temp = test[j]; test[j] = test[j+1]; test[j+1] = temp; flag = true; } } if (flag == false){ break; } } return test; }
时间复杂度:O(n^2)