Profile image for Dominic Charley-Roy jokeofweek
This is a basic implementation of the Shell sort to sort arrays of integers.
Language
Java
Tags
algorithm array java shell sort
Favorited By
Profile image for shafiq ahamed

Shell Sort

1 public class ShellSort { 2 public static int[] sort(int[] arr) 3 { 4 5 int position = Math.round(arr.length/2); 6 int temp=0; 7 int j=0; 8 9 while (position > 0) 10 { 11 for (int i=position;i<arr.length;i++) 12 { 13 temp = arr[i]; 14 j=i; 15 while (j>position && arr[j-position] > temp) 16 { 17 arr[j] = arr[j-position]; 18 j=j-position; 19 } 20 arr[j]=temp; 21 } 22 23 position = Math.round(position/2); 24 } 25 26 return arr; 27 } 28 }

Comments