forked from AllAlgorithms/java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.java
More file actions
Latest commit
36 lines (29 loc) · 824 Bytes
/
Copy pathShellSort.java
File metadata and controls
36 lines (29 loc) · 824 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
29
30
31
32
33
34
35
36
/**
* Java implementation of merge sort
*
* @author Dimitris Glynatsis
* @email dim.glynatsis@gmail.com
*/
publicclassShellSort {
staticvoidshell(int[] a) {
intl = 0, r = a.length - 1, h;
for (h = 0; h <= (r - 1) / 9; h = 3 * h + 1)
;
for (; h > 0; h /= 3)
for (inti = l + h; i <= r; i++) {
intj = i, v = a[i];
while (j >= l + h && v < a[j - h]) {
a[j] = a[j - h];
j -= h;
}
a[j] = v;
}
}
publicstaticvoidmain(String[] args) {
int[] a = { 5, 6, 4, 9, 13, 3, 7 };
ShellSorts = newShellSort();
s.shell(a);
for (inti = 0; i < a.length; i++)
System.out.println(a[i]);
}
}