import java.util.Arrays; public class SortJava { public static void main(String[] args) { int []arr = {34,9,15,62,8,432,6,54,457,65,4}; insertSort(arr); System.out.println(Arrays.toString(arr)); } //插入排序 private static void insertSort(int[] arr) { for(int i = 1 ;i<arr.length;i++) { int temp = arr[i]; int j; for(j =i-1; j>=0&&arr[j]>temp;j--) { arr[j+1] = arr[j]; } arr[j+1] = temp; } } //选择排序 private static void selectSort(int[] arr) { int indexOfMin = 0; for(int i = 0;i<arr.length-1;i++){ indexOfMin = i; for(int j = i+1; j<arr.length;j++) { if(arr[indexOfMin]>arr[j]) { indexOfMin = j; //找到值最小的坐标 } } if(i!=indexOfMin) { int temp = arr[i]; arr[i] = arr[indexOfMin]; arr[indexOfMin] = temp; } } } //冒泡排序 private static void bubbleSort(int[] arr) { for(int i = 0;i<arr.length-1;i++) { for(int j=i+1;j<arr.length;j++) { if(arr[i]>arr[j]) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } } }