public void insertSort(List<Integer> list) {
for (int i = 1; 1 < list.size(); i++) {
int ele = list.get(i);
int k = i - 1;
while (k >= 0 && list.get(k) > ele) {
list.set(k + 1, list.get(k));
k--;
}
list.set(k + 1, ele);
}
}
参照 冒泡排序可视化