Hill sort 8th Section Hill sort Exercises
For an int array, write a hill sorting algorithm that sorts the elements of the array.
Given an int array a and the size of the array n, return the sorted array. Guaranteed element is less than or equal to 2000.
Test examples:
[1,2,3,5,2,3],6
[1,2,2,3,3,5]
Java (javac 1.7)Code Auto-Complete1
Import Java. util. *;
2
3
Public class Shellsort {
4
Public int Shellsort (intAintn) {
5
int I Step //i Identify each group, step identification step
6
for (step=n/2step>0 step /= 2 //Start step is half of the length of the array
7
for (i=stepI<ni+ +//Current step is step, Start Insert Sort
8
if (a[i<a[i-step ]
9
int Target = A [i];
10
int J = I //j indicates which element the current group traverses to
11
while (J>0&&A[J-step> target) {
12
A [j=A[J-step//Move the element on the j-step position to position J
13
J -= step;
14
if (J-step<0) //If j=1,step=3, there is no such if, the array is out of bounds
15
break;
16
}
17
A [j=target;
18
}
19
}
20
}
21st
return A;
22
}
23
}
Your code is saved
The answer is right: Congratulations! The program you submitted passed all of the test cases
Algorithm-java code implements Hill sort