Sort an integer array: Difference between revisions

Content added Content deleted
(→‎BQN: add)
Line 756: Line 756:
^-1p0\0:< ^-1 p0\+1 g0:&< ^-1\.:\<
^-1p0\0:< ^-1 p0\+1 g0:&< ^-1\.:\<
^ <</syntaxhighlight>
^ <</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}}==
=={{header|Bracmat}}==
Line 786: Line 791:
out$sort$(9 -2 1 2 8 0 1 2);</syntaxhighlight>
out$sort$(9 -2 1 2 8 0 1 2);</syntaxhighlight>
{{out}}
Output:
<pre>-2 0 1 1 2 2 8 9</pre>
<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.
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.