将特定子数组末尾的元素插入其前面数组其余部分的排序位置
//package com.nowjava;/*from NowJava.com - 时 代 Java*/ import java.util.ArrayList; public class Main { /** * inserts the element at the end of a particular sub-array into its sorted position in the rest of the array before it * * @param arrayList the ArrayList with an element that you want to insert in order * @param sortedStart the index of the first element in the sorted subset of the array. all elements between this and * $unsortedStart are sorted * @param unsortedStart the index of arrayList that marks the element that you want to insert into the sorted section. * it could already be in the right place, but we're not sure. */ public static <T extends Comparable<? super T>> void insertInOrder( ArrayList<T> arrayList, int sortedStart, int unsortedStart) { T insertElement = arrayList.get(unsortedStart); int insertIndex = unsortedStart; while (insertIndex != sortedStart && insertElement.compareTo(arrayList.get(insertIndex - 1)) == -1) {