@@ -0,0 +1,1408 @@
+// Java implementation of ShellSort%0Aclass ShellSort%0A%7B%0A%09/* An utility function to print array of size n*/%0A%09static void printArray(int arr%5B%5D)%0A%09%7B%0A%09%09int n = arr.length;%0A%09%09for (int i=0; i%3Cn; ++i)%0A%09%09%09System.out.print(arr%5Bi%5D + %22 %22);%0A%09%09System.out.println();%0A%09%7D%0A%0A%09/* function to sort arr using shellSort */%0A%09int sort(int arr%5B%5D)%0A%09%7B%0A%09%09int n = arr.length;%0A%0A%09%09// Start with a big gap, then reduce the gap%0A%09%09for (int gap = n/2; gap %3E 0; gap /= 2)%0A%09%09%7B%0A%09%09%09// Do a gapped insertion sort for this gap size.%0A%09%09%09// The first gap elements a%5B0..gap-1%5D are already%0A%09%09%09// in gapped order keep adding one more element%0A%09%09%09// until the entire array is gap sorted%0A%09%09%09for (int i = gap; i %3C n; i += 1)%0A%09%09%09%7B%0A%09%09%09%09// add a%5Bi%5D to the elements that have been gap%0A%09%09%09%09// sorted save a%5Bi%5D in temp and make a hole at%0A%09%09%09%09// position i%0A%09%09%09%09int temp = arr%5Bi%5D;%0A%0A%09%09%09%09// shift earlier gap-sorted elements up until%0A%09%09%09%09// the correct location for a%5Bi%5D is found%0A%09%09%09%09int j;%0A%09%09%09%09for (j = i; j %3E= gap && arr%5Bj - gap%5D %3E temp; j -= gap)%0A%09%09%09%09%09arr%5Bj%5D = arr%5Bj - gap%5D;%0A%0A%09%09%09%09// put temp (the original a%5Bi%5D) in its correct%0A%09%09%09%09// location%0A%09%09%09%09arr%5Bj%5D = temp;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return 0;%0A%09%7D%0A%0A%09// Driver method%0A%09public static void main(String args%5B%5D)%0A%09%7B%0A%09%09int arr%5B%5D = %7B12, 34, 54, 2, 3%7D;%0A%09%09System.out.println(%22Array before sorting%22);%0A%09%09printArray(arr);%0A%0A%09%09ShellSort ob = new ShellSort();%0A%09%09ob.sort(arr);%0A%0A%09%09System.out.println(%22Array after sorting%22);%0A%09%09printArray(arr);%0A%09%7D%0A%7D%0A

add ShellSort implementation in java