图示
代码
public static void xrpx(ArrayList<Integer> data){
if(data.size()<=1)
return;
int divisor = data.size();
int length = data.size();
int index; //记录当前要操作的数据下标
int temp; //存放要操作的数据的值
int record; //索引
while (divisor>1){
divisor /= 2;
//从第divisor个元素开始,逐个排序,排序时只在组里排
for (index = divisor; index < length; index++) {
record = index;
temp = data.get(index);
//从当前index开始,步长为divisor,验证有下一个且下一个较大,则后移
while (record - divisor >= 0 && temp < data.get(record-divisor)){
data.set(record,data.get(record-divisor));
record -= divisor;
}
//退出while时找到位置
data.set(record,temp);
}
}
}