Home > Back-end >  Hill sorting error
Hill sorting error

Time:10-08

 
Package com. Zx. Practice;

import java.util.Arrays;

Public class ShellSort {

Public static void main (String [] args) {
Int [] arr=,5,2,7,6,4,9,8 {3};
ShellSort (arr);
System. The out. Print (Arrays. ToString (arr));
}

Public static void shellSort (int [] arr) {
For (int I=arr. Length/2; i>=1; I/=2) {
For (int j=0; J & lt; Arr. Length - I; J++) {
Int insertVal=arr [j + I);
Int insertIndex=j;
While (insertIndex & gt;=0 & amp; & InsertVal & gt; Arr [insertIndex]) {
Arr=arr + I [j] [insertIndex];
InsertIndex -=I;
}
Arr [insertIndex + I]=insertVal;
}
}
}

}

Output: [8, 9, 5, 6, 5, 3, 2, 4],
  • Related