We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent db74c11 commit 624cefeCopy full SHA for 624cefe
src/io/uuddlrlrba/ktalgs/sorts/ShellSort.kt
@@ -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
+}
src/io/uuddlrlrba/ktalgs/sorts/ShellSortTest.kt
@@ -0,0 +1,3 @@
+class ShellSortTest: AbstractSortTest<ShellSort>(ShellSort())
0 commit comments