-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.java
More file actions
28 lines (23 loc) · 749 Bytes
/
ShellSort.java
File metadata and controls
28 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package SortAlgorithms;
import java.util.Arrays;
/**
* @author : J. Andrés Boyacá Silva
* @since : 8/25/2020, Tue
**/
public class ShellSort {
public static void main(String[] args) {
int[] intArray = {35, 45, -50, 12, 18, 55, 75};
for (int gap = intArray.length / 2; gap > 0; gap /= 2) {
for (int i = gap; i < intArray.length; i++) {
int newElement = intArray[i];
int j = i;
while (j >= gap && intArray[j - gap] > newElement) {
intArray[j] = intArray[j - gap];
j -= gap;
}
intArray[j] = newElement;
}
}
System.out.println(Arrays.toString(intArray));
}
}