public class ShellSort {
public static <T extends Comparable<? super T>> void shellSort(T[] array, int len) {
int d = len;
while (d > 1) {
d = (d + 1) / 2;
for (int i = 0; i < len - d; i++) {
if (array[i + d].compareTo(array[i]) < 0) {
T temp = array[i + d];
array[i + d] = array[i];
array[i] = temp;
}
}
}
}
public static void main(String[] args) {
Integer[] testArray = {23, 25, 12, 42, 35};
ShellSort.shellSort(testArray, 5);
System.out.println("The result is:");
for (Integer item : testArray) {
System.out.print(item);
System.out.print(' ');
}
}
}
最近下载更多
* LV1
2021年9月2日
shoushou70 LV2
2016年7月20日
爱呀码啊 LV1
2015年11月16日
chellong LV8
2015年10月16日
holysir LV28
2013年12月29日
最近浏览更多
微信网友_6914242492977152
2024年3月19日
暂无贡献等级
四十四十 LV3
2023年11月1日
微信网友_6040315240812544 LV8
2022年10月27日
myh7719 LV2
2022年6月13日
1145304128 LV12
2022年4月1日
* LV1
2021年9月2日
OMITUUID LV6
2021年5月22日
zhangjilu LV18
2020年7月14日
Jacko01 LV8
2020年6月15日
25324521 LV1
2020年4月23日

