Sort an integer array: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Minor tidy) |
||
(7 intermediate revisions by 6 users not shown) | |||
Line 756:
^-1p0\0:< ^-1 p0\+1 g0:&< ^-1\.:\<
^ <</syntaxhighlight>
=={{header|BQN}}==
<syntaxhighlight lang="bqn">∧ [4, 1, 2, ¯9, ¯5, 3, 6, 9, ¯2]</syntaxhighlight>
{{out}}
<pre>⟨ ¯9 ¯5 ¯2 1 2 3 4 6 9 ⟩</pre>
=={{header|Bracmat}}==
Line 786 ⟶ 791:
out$sort$(9 -2 1 2 8 0 1 2);</syntaxhighlight>
{{out}}
<pre>-2 0 1 1 2 2 8 9</pre>
This solution becomes very ineffective for long lists. To add a single term to an already sorted sum of N terms requires on average N/2 steps. It is much more efficient to merge two already sorted sums of about equal length.
Line 1,207 ⟶ 1,212:
[-42, 2, 2, 5, 78, 578]
[578, 78, 5, 2, 2, -42]
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
window 1, @"Sort an integer array"
void local fn DoIt
CFArrayRef array = @[@13,@71,@42,@8,@5,@27]
array = fn ArraySortedArrayUsingSelector( array, @"compare:" )
print fn ArrayComponentsJoinedByString( array, @", " )
end fn
fn DoIt
HandleEvents
</syntaxhighlight>
{{out}}
<pre>
5, 8, 13, 27, 42, 71
</pre>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sort_an_integer_array}}
'''Solution'''
[[File:Fōrmulæ - Sort an integer array 01.png]]
[[File:Fōrmulæ - Sort an integer array 02.png]]
=={{header|Gambas}}==
Line 2,306 ⟶ 2,332:
see sort(aArray)</syntaxhighlight>
=={{header|RPL}}==
{{works with|HP|48G}}
{2 4 3 1 2} SORT
{{out}}
<pre>
1: { 1 2 2 3 4 }
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">nums = [2,4,3,1,2]
Line 2,408 ⟶ 2,441:
or destructive:
<syntaxhighlight lang="smalltalk"> #(7 5 2 9 0 -1) sort</syntaxhighlight>
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "int_sort" )
@( description, "Sort an array (or list) of integers in ascending" )
@( description, "numerical order. Use a sorting facility provided by" )
@( description, "the language/library if possible." )
@( category, "tutorials" )
@( author, "Ken O. Burtch" )
@( see_also, "http://rosettacode.org/wiki/Sort_an_integer_array" );
pragma license( unrestricted );
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
procedure int_sort is
type int_array is array (1..9) of integer;
int_values : int_array := (0,1,8,2,7,3,6,4,5);
begin
arrays.heap_sort( int_values );
for i in arrays.first( int_values )..arrays.last( int_values ) loop
? int_values(i);
end loop;
end int_sort;</syntaxhighlight>
=={{header|Sparkling}}==
Line 2,600 ⟶ 2,658:
<pre><5,14,23,39,40,40,41,47,52,53,62,66,78,88,88,92></pre>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
mut nums := [3, 2, 4, 1, 6, 7, 5, 0]
nums.sort()
Line 2,621 ⟶ 2,679:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="
var a = [7, 10, 2, 4, 6, 1, 8, 3, 9, 5]
|