package SortAlgorithms; import UI.AnimationPanel; public class Insertion { public volatile static int changing; public volatile static int position; @SuppressWarnings("rawtypes") public static void sort(final Comparable[] a) { new Thread() { @Override public void run() { for (int i = 1; i < a.length; i++) for (int j = i; j > 0; j--) if (less(a[j], a[j - 1])) { if (!AnimationPanel.threadContinue) return; try { sleep(AnimationPanel.SPF); } catch (InterruptedException e) { e.printStackTrace(); } position = i; changing = j - 1; exch(a, j, j - 1); } }; }.start(); } @SuppressWarnings("rawtypes") private static void exch(Comparable[] a, int i, int j) { Comparable tmp = a[i]; a[i] = a[j]; a[j] = tmp; } @SuppressWarnings({ "rawtypes", "unchecked" }) private static boolean less(Comparable x, Comparable y) { return x.compareTo(y) < 0; } @SuppressWarnings("rawtypes") public static void show(Comparable[] a) { for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } @SuppressWarnings("rawtypes") public static boolean isSorted(Comparable[] a) { for (int i = 1; i < a.length; i++) if (less(a[i], a[i - 1])) return false; return true; } }

xingxing1234 LV10
2023年3月22日
WASDZZ LV13
2021年10月27日
zm2580hh LV1
2021年1月15日
cyszzc LV1
2020年12月16日
最代码官方 LV168
2020年5月31日
黄泽文 LV1
2020年5月25日
wei1101025 LV15
2020年3月24日
ysc123 LV5
2020年2月21日
wzx2e3 LV1
2019年12月22日
1147692290 LV1
2019年8月24日

xingxing1234 LV10
2023年3月22日
微信网友_6040315240812544 LV8
2022年10月27日
liys1234 LV9
2022年4月22日
1265260263 LV4
2022年4月8日
fudonglin0514 LV6
2021年12月4日
WASDZZ LV13
2021年10月27日
v LV1
2021年6月12日
ham123456
2021年4月16日
暂无贡献等级
zm2580hh LV1
2021年1月15日
cyszzc LV1
2020年12月16日