Jump to content

Sort an integer array: Difference between revisions

(→‎BQN: add)
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}}
Output:
<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.
559

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.