/**
时代Java公众号 - nowjava.com 提供
**/
public class shellSort
{
public void sort(int input[]) // Function implementing Insertion Sort
{
int n = input.length, temp, j;
for (int gap = n / 2; gap > 0; gap /= 2)
{
for (int i = gap; i < n; i++) // Gapped insertion sort
{
temp = input[i];
for (j = i; j >= gap && input[j - gap] > temp; j = j - gap)
input[j] = input[j - gap];/* from n o w j a v a . c o m - 时代Java*/
input[j] = temp;
}
}
}
public static void main(String[] args)
{
int input[] = {5, 6, 8, 4, 6, 5, 3, 3, 2, 7, 8, 45, 85, 96}; //Input array
shellSort ob = new shellSort();
ob.sort(input);
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。