public class InsertionSort {
public static void main(String[] args) {
int[] aa = { 49, 38, 65, 97, 76, 13, 27 };
int[] result = new InsertionSortJava().insertionSort(aa);
for (int s : result) {
System.out.println(s);
}
}
}
class InsertionSortJava {
int[] insertionSort(int[] a) {
int j;
for (int p = 1; p < a.length; p++) {
int tmp = a[p];
for (j = p; j > 0 && tmp < a[j - 1]; j--) {
a[j] = a[j - 1];
}
a[j] = tmp;
}
return a;
}
}
Java 直接插入排序
最新推荐文章于 2024-07-24 17:27:32 发布