Skip to content

Commit 624cefe

Browse files
committed
add(sorts): Shell
1 parent db74c11 commit 624cefe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.uuddlrlrba.ktalgs.sorts
2+
3+
class ShellSort : AbstractSortStrategy() {
4+
public override fun<T : Comparable<T>> perform(arr: Array<T>) {
5+
var h = 1
6+
while (h < arr.size / 3) {
7+
h = h * 3 + 1
8+
}
9+
10+
while (h >= 1) {
11+
for (i in h..arr.size - 1) {
12+
for (j in i downTo h step h) {
13+
if (arr[j - h] < arr[j]) break
14+
exch(arr, j, j - h)
15+
}
16+
}
17+
h /= 3
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.uuddlrlrba.ktalgs.sorts
2+
3+
class ShellSortTest: AbstractSortTest<ShellSort>(ShellSort())

0 commit comments

Comments
 (0)