Commit f82f003
committed
fix: bubble sort no longer fails on reversed array
A corner case in the end condition of bubble sort meant that if the
array ever got to a state where the unsorted subarray is size 2 and out
of order, i.e. _end = 2 AND array[0] > array[1] (starting with a
reversed array will lead to this condition), the next iteration will
have _index equal _end, missing the end condition entirely and
eventually causing a crash when the player goes outside the array
bounds.1 parent ff6a4d7 commit f82f003
2 files changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
0 commit comments