nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed quick_sort when array is length 0 or 1
[nit.git]
/
lib
/
core
/
collection
/
sorter.nit
diff --git
a/lib/core/collection/sorter.nit
b/lib/core/collection/sorter.nit
index
9157995
..
7476b6f
100644
(file)
--- a/
lib/core/collection/sorter.nit
+++ b/
lib/core/collection/sorter.nit
@@
-106,7
+106,14
@@
interface Comparator
# var a = [5, 2, 3, 1, 4]
# default_comparator.quick_sort(a, 0, a.length - 1)
# assert a == [1, 2, 3, 4, 5]
# var a = [5, 2, 3, 1, 4]
# default_comparator.quick_sort(a, 0, a.length - 1)
# assert a == [1, 2, 3, 4, 5]
+ # var a2 = new Array[Int]
+ # default_comparator.quick_sort(a2, 0, a2.length - 1)
+ # assert a2 == new Array[Int]
+ # var a3 = [1]
+ # default_comparator.quick_sort(a3, 0, a3.length - 1)
+ # assert a3 == [1]
fun quick_sort(array: Array[COMPARED], from: Int, to: Int) do
fun quick_sort(array: Array[COMPARED], from: Int, to: Int) do
+ if from >= to then return
var pivot = array[from]
var i = from
var j = to
var pivot = array[from]
var i = from
var j = to