Sort stability: Difference between revisions
Content added Content deleted
(adding gap, but not sure !) |
(→{{header|GAP}}: more readable I hope) |
||
Line 83:
=={{header|GAP}}==
<lang gap># According to section 21.18 of the reference manual, Sort is not stable
# However, SortingPerm is stable. We will see it on an example, showing indexes of elements after the sort.
s:=List([1 .. 40], n -> Random("AB"));▼
n := 20;
p:=SortingPerm(s);▼
# "AABABBBABBABAABABBAB"
Permuted([1 .. 40], p);▼
# (3,10,15,17,18,19,9,14,7,13,6,12,16,8,4)(5,11)
a := Permuted(L, p);;
PrintArray(TransposedMat(List([1 .. n], i -> [a[i], b[i]])));
# [ [ 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B' ],
# [ 1, 2, 4, 8, 11, 13, 14, 16, 19, 3, 5, 6, 7, 9, 10, 12, 15, 17, 18, 20 ] ]</lang>
=={{header|Go}}==
|