File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
src/main/scala/algorithms/sort Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ def timSort(arr: Array[Int], k: Int = 64): Unit = {
12
12
13
13
val n = arr.length
14
14
15
- // Step 1: Sort small chunks with Insertion Sort
15
+ // Sort small chunks with Insertion Sort
16
16
for (i <- 0 until n by k) {
17
17
val end = Math .min(i + k, n)
18
- insertionSortInPlace (arr, i, end)
18
+ subArrayInsertionSort (arr, i, end)
19
19
}
20
20
21
- // Step 2: Merge sorted chunks with Merge Sort
21
+ // Merge sorted chunks with Merge Sort
22
22
var size = k
23
23
while (size < n) {
24
24
for (left <- 0 until n by 2 * size) {
@@ -32,7 +32,7 @@ def timSort(arr: Array[Int], k: Int = 64): Unit = {
32
32
}
33
33
34
34
// Helper function: Insertion Sort for a subarray
35
- private def insertionSortInPlace (arr : Array [Int ], start : Int , end : Int ): Unit = {
35
+ private def subArrayInsertionSort (arr : Array [Int ], start : Int , end : Int ): Unit = {
36
36
for (i <- start + 1 until end) {
37
37
val key = arr(i)
38
38
var j = i - 1
You can’t perform that action at this time.
0 commit comments