Sort an integer array: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
m (→{{header|Wren}}: Minor tidy) |
||
(5 intermediate revisions by 4 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,230 ⟶ 1,235:
=={{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,325 ⟶ 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,427 ⟶ 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,640 ⟶ 2,679:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="
var a = [7, 10, 2, 4, 6, 1, 8, 3, 9, 5]
|