Sort an integer array: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 28:
TRIER TABLEAU($nombres) ` pour effectuer un tri par ordre croissant
TRIER TABLEAU($nombres;<) ` pour effectuer un tri par ordre décroissant</lang>
 
=={{header|8th}}==
<lang forth>
Line 152 ⟶ 153:
X[⍋X]
15 36 39 43 51 63 69 89 92 92</lang>
 
 
=={{header|AppleScript}}==
Line 230:
8
9</pre>
 
 
=={{header|AutoHotkey}}==
Line 403 ⟶ 402:
 
''Caution:'' An older version of <tt>intcmp()</tt> did <tt>return *a - *b</tt>. This is only correct when the subtraction does not overflow. Suppose that <tt>*a = 2000000000</tt> and <tt>*b = -2000000000</tt> on a machine with 32-bit <tt>int</tt>. The subtraction <tt>*a - *b</tt> would overflow to <tt>-294967296</tt>, and <tt>intcmp()</tt> would believe <tt>*a < *b</tt>, but the correct answer is <tt>*a > *b</tt>.
 
=={{header|C sharp|C#}}==
 
<lang csharp>using System;
using System.Collections.Generic;
 
public class Program {
static void Main() {
int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
Array.Sort(unsorted);
}
}</lang>
 
=={{header|C++}}==
Line 446 ⟶ 457:
nums.sort();
return 0;
}</lang>
 
=={{header|C sharp|C#}}==
 
<lang csharp>using System;
using System.Collections.Generic;
 
public class Program {
static void Main() {
int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
Array.Sort(unsorted);
}
}</lang>
 
Line 537 ⟶ 536:
TArray.Sort<Integer>(a);
end;</lang>
=={{header|Déjà Vu}}==
<lang dejavu>!. sort [ 5 4 3 2 1 ]</lang>
{{out}}
<pre>[ 1 2 3 4 5 ]</pre>
 
=={{header|DWScript}}==
Line 546 ⟶ 541:
a.Sort; // ascending natural sort
PrintLn(a.Map(IntToStr).Join(',')); // 1,2,3,4,5</lang>
 
=={{header|Déjà Vu}}==
<lang dejavu>!. sort [ 5 4 3 2 1 ]</lang>
{{out}}
<pre>[ 1 2 3 4 5 ]</pre>
 
=={{header|E}}==
<lang e>[2,4,3,1,2].sort()</lang>
 
=={{header|EGL}}==
{{works with|EDT}}
The following works in EDT with Rich UI and stand-alone programs.
<lang EGL>program SortExample
 
function main()
test1 int[] = [1,-1,8,-8,2,-2,7,-7,3,-3,6,-6,9,-9,4,-4,5,-5,0];
test1.sort(sortFunction);
 
for(i int from 1 to test1.getSize())
SysLib.writeStdout(test1[i]);
end
end
function sortFunction(a any in, b any in) returns (int)
return (a as int) - (b as int);
end
end</lang>
{{works with|RBD}}
The following works in RBD but only with Rich UI programs.
<lang EGL>test1 int[] = [1,-1,8,-8,2,-2,7,-7,3,-3,6,-6,9,-9,4,-4,5,-5,0];
RUILib.sort(test1, sortFunction);
 
function sortFunction(a any in, b any in) returns (int)
return ((a as int) - (b as int));
end</lang>
 
=={{header|Elena}}==
ELENA 5.0 :
Line 580 ⟶ 610:
print(1,sort({20, 7, 65, 10, 3, 0, 8, -60}))</lang>
 
=={{header|EGLF_Sharp|F#}}==
<lang fsharp>// sorting an array in place
{{works with|EDT}}
let nums = [| 2; 4; 3; 1; 2 |]
The following works in EDT with Rich UI and stand-alone programs.
Array.sortInPlace nums
<lang EGL>program SortExample
 
// create a sorted copy of a list
function main()
let nums2 = [2; 4; 3; 1; 2]
test1 int[] = [1,-1,8,-8,2,-2,7,-7,3,-3,6,-6,9,-9,4,-4,5,-5,0];
let sorted = List.sort nums2</lang>
test1.sort(sortFunction);
 
for(i int from 1 to test1.getSize())
SysLib.writeStdout(test1[i]);
end
end
function sortFunction(a any in, b any in) returns (int)
return (a as int) - (b as int);
end
end</lang>
{{works with|RBD}}
The following works in RBD but only with Rich UI programs.
<lang EGL>test1 int[] = [1,-1,8,-8,2,-2,7,-7,3,-3,6,-6,9,-9,4,-4,5,-5,0];
RUILib.sort(test1, sortFunction);
 
function sortFunction(a any in, b any in) returns (int)
return ((a as int) - (b as int));
end</lang>
 
=={{header|Factor}}==
Line 759 ⟶ 769:
<lang frink>a = [5, 2, 4, 1, 6, 7, 9, 3, 8, 0]
sort[a]</lang>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>// sorting an array in place
let nums = [| 2; 4; 3; 1; 2 |]
Array.sortInPlace nums
 
// create a sorted copy of a list
let nums2 = [2; 4; 3; 1; 2]
let sorted = List.sort nums2</lang>
 
=={{header|FunL}}==
Line 780 ⟶ 781:
[578, 78, 5, 2, 2, -42]
</pre>
 
=={{header|GAP}}==
<lang gap>a := [ 8, 2, 5, 9, 1, 3, 6, 7, 4 ];
# Make a copy (with "b := a;", b and a would point to the same list)
b := ShallowCopy(a);
 
# Sort in place
Sort(a);
a;
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
 
# Sort without changing the argument
SortedList(b);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b;
# [ 8, 2, 5, 9, 1, 3, 6, 7, 4 ]</lang>
 
=={{header|Gambas}}==
Line 816 ⟶ 801:
1, 2, 3, 4, 5, 6, 7, 8, 9
</pre>
 
=={{header|GAP}}==
<lang gap>a := [ 8, 2, 5, 9, 1, 3, 6, 7, 4 ];
# Make a copy (with "b := a;", b and a would point to the same list)
b := ShallowCopy(a);
 
# Sort in place
Sort(a);
a;
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
 
# Sort without changing the argument
SortedList(b);
# [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
b;
# [ 8, 2, 5, 9, 1, 3, 6, 7, 4 ]</lang>
 
=={{header|Go}}==
Line 854 ⟶ 855:
nums.sort();
}</lang>
 
=={{header|IDL}}==
<lang idl>result = array[sort(array)]</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 863 ⟶ 861:
In the example below, L will remain an unsorted list and S will be sorted.
<lang Icon>S := sort(L:= [63, 92, 51, 92, 39, 15, 43, 89, 36, 69]) # will sort a list</lang>
 
=={{header|IDL}}==
<lang idl>result = array[sort(array)]</lang>
 
=={{header|Inform 7}}==
Line 922 ⟶ 923:
numbers.sort(int_arr);
document.write(numbers);</lang>
 
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
 
fun main(args: Array<String>) {
val ints = intArrayOf(6, 2, 7, 8, 3, 1, 10, 5, 4, 9)
ints.sort()
println(ints.joinToString(prefix = "[", postfix = "]"))
}</lang>
 
{{out}}
<pre>
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</pre>
 
=={{header|Lasso}}==
<lang Lasso>local(array) = array(5,20,3,2,6,1,4)
#array->sort
#array // 1, 2, 3, 4, 5, 6, 20
 
// Reverse the sort order
#array->sort(false)
#array // 20, 6, 5, 4, 3, 2, 1</lang>
 
=={{header|jq}}==
Line 993 ⟶ 971:
srt num
0 1 2 3 4 5 6 7 8 9</lang>
 
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
 
fun main(args: Array<String>) {
val ints = intArrayOf(6, 2, 7, 8, 3, 1, 10, 5, 4, 9)
ints.sort()
println(ints.joinToString(prefix = "[", postfix = "]"))
}</lang>
 
{{out}}
<pre>
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</pre>
 
=={{header|Lasso}}==
<lang Lasso>local(array) = array(5,20,3,2,6,1,4)
#array->sort
#array // 1, 2, 3, 4, 5, 6, 20
 
// Reverse the sort order
#array->sort(false)
#array // 20, 6, 5, 4, 3, 2, 1</lang>
 
=={{header|Liberty BASIC}}==
Line 1,416 ⟶ 1,417:
<lang Niue>2 6 1 0 3 8 sort .s
0 1 2 3 6 8</lang>
 
=={{header|Objective-C}}==
<lang objc>NSArray *nums = @[@2, @4, @3, @1, @2];
NSArray *sorted = [nums sortedArrayUsingSelector:@selector(compare:)];</lang>
 
=={{header|Objeck}}==
Line 1,430 ⟶ 1,427:
}
}</lang>
 
=={{header|Objective-C}}==
<lang objc>NSArray *nums = @[@2, @4, @3, @1, @2];
NSArray *sorted = [nums sortedArrayUsingSelector:@selector(compare:)];</lang>
 
=={{header|OCaml}}==
Line 1,520 ⟶ 1,521:
<lang perl>@nums = (2,4,3,1,2);
@sorted = sort {$a <=> $b} @nums;</lang>
 
=={{header|Perl 6}}==
If <code>@a</code> contains only numbers:
 
<lang perl6>my @sorted = sort @a;</lang>
 
For an in-place sort:
 
<lang perl6>@a .= sort;</lang>
 
=={{header|Phix}}==
Line 1,669 ⟶ 1,661:
'(1 2 3 4 5 6 7 8 9)
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
If <code>@a</code> contains only numbers:
 
<lang perl6>my @sorted = sort @a;</lang>
 
For an in-place sort:
 
<lang perl6>@a .= sort;</lang>
 
=={{header|Rascal}}==
10,327

edits