@@ -8,27 +8,27 @@ return function(
8
8
return a < b
9
9
end
10
10
-- Merges two sorted lists; elements of a come before those of b
11
- local function merge (result , list , other_list )
11
+ local function merge (result , list_1 , list_2 )
12
12
local result_index = 1
13
- local index = 1
14
- local other_index = 1
15
- while index <= # list and other_index <= # other_list do
13
+ local index_1 = 1
14
+ local index_2 = 1
15
+ while index_1 <= # list_1 and index_2 <= # list_2 do
16
16
-- Compare "head" element, insert "winner"
17
- if less_than (other_list [ other_index ], list [ index ]) then
18
- result [result_index ] = other_list [ other_index ]
19
- other_index = other_index + 1
17
+ if less_than (list_2 [ index_2 ], list_1 [ index_1 ]) then
18
+ result [result_index ] = list_2 [ index_2 ]
19
+ index_2 = index_2 + 1
20
20
else
21
- result [result_index ] = list [ index ]
22
- index = index + 1
21
+ result [result_index ] = list_1 [ index_1 ]
22
+ index_1 = index_1 + 1
23
23
end
24
24
result_index = result_index + 1
25
25
end
26
26
-- Add remaining elements of either list or other_list
27
- for offset = 0 , # list - index do
28
- result [result_index + offset ] = list [ index + offset ]
27
+ for offset = 0 , # list_1 - index_1 do
28
+ result [result_index + offset ] = list_1 [ index_1 + offset ]
29
29
end
30
- for offset = 0 , # other_list - other_index do
31
- result [result_index + offset ] = other_list [ other_index + offset ]
30
+ for offset = 0 , # list_2 - index_2 do
31
+ result [result_index + offset ] = list_2 [ index_2 + offset ]
32
32
end
33
33
end
34
34
0 commit comments