package sort;
public class ShellSort {
public static void main(String[] args) {
int[] arr=new int[] {34,23,45,-56,76,8,4,34,0};
System.out.println("before sorting");
for(int a:arr) {
System.out.printf("%d\t",a);
}
shellSort(arr);
System.out.println("\nafter sorting");
for(int a:arr) {
System.out.printf("%d\t",a);
}
}
public static void shellSort(int[] arr) {
int temp = 0;
for (int gap = arr.length / 2; gap > 0; gap /= 2) {
for (int i = gap; i < arr.length; i++) {
for (int j = i - gap; j >= 0; j -= gap) {
if (arr[j] > arr[j + gap]) {
temp = arr[j];
arr[j] = arr[j + gap];
arr[j + gap] = temp;
}
}
}
}
}
}