标签:print 排序 rgs for import str tostring while arrays
import java.util.Arrays; public class InsertSort { public static void main(String[] args) { int[] a = { 21, 4, 6, 34, 54, 2 }; System.out.println(Arrays.toString(a)); insertsort(a); System.out.println(Arrays.toString(a)); } public static void insertsort(int[] arr) { for (int i = 1; i < arr.length; i++) { int tmp = arr[i];// 要插入的数 int j = i - 1; while (j >= 0 && tmp < arr[j]) {// 后移 arr[j + 1] = arr[j]; j--; } arr[j + 1] = tmp; } } }
标签:print 排序 rgs for import str tostring while arrays
原文地址:http://www.cnblogs.com/Tan-Yin-Yin-19971130/p/7956073.html