Skip to content

Commit a7a1131

Browse files
committed
Fix bug on cocktail shaker sort with reversed data
1 parent 5de16ac commit a7a1131

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

levels/cocktail_shaker_sort.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ACTIONS = {
3636
"CONTINUE": "Right",
3737
}
3838
var _index = 0 # First of two elements being compared
39-
var _sorted = 0 # Size of the sorted subarray at the end of the array
39+
var _sorted = 0 # Size of the sorted subarrays at the two ends of the array
4040
var _forwards = true
4141
var _swapped = false
4242

@@ -61,6 +61,8 @@ func next(action):
6161
_forwards = false
6262
_index -= 2
6363
_sorted += 1
64+
if _sorted == array.size / 2:
65+
emit_signal("done")
6466
else:
6567
_index -= 1
6668
if _index == _sorted - 2:

levels/merge_sort.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class_name MergeSort
22
extends ComparisonSort
33

4+
# BUG: Crashes on array sizes that are not powers of two
5+
46
const NAME = "MERGE SORT"
57
const DESCRIPTION = """
68
Merge sort merges subarrays of increasing size by setting a pointer to

0 commit comments

Comments
 (0)