Anonymous user
Sorting algorithms/Permutation sort: Difference between revisions
Sorting algorithms/Permutation sort (view source)
Revision as of 00:43, 31 August 2017
, 6 years ago→{{header|REXX}}: added/changed comments and whitespace, brought a function in-line, aligned some statements, used template for output.
(Added Julia language) |
m (→{{header|REXX}}: added/changed comments and whitespace, brought a function in-line, aligned some statements, used template for output.) |
||
Line 1,479:
call show 'before sort' /*show the before array elements. */
say copies('░', 75) /*show separator line between displays.*/
call
call pSort L /*invoke the permutation sort. */▼
call show ' after sort' /*show the after array elements. */
say; say 'Permutation sort took ' ? " permutations to find the sorted list."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
.pAdd: #=#+1; do j=1 for N;
show: do j=1 for L; say
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: @.=; @.1 = '---Four_horsemen_of_the_Apocalypse---'
@.2 = '====================================='
@.3 = 'Famine───black_horse'
@.4 = 'Death───pale_horse'
@.5 = 'Pestilence_[Slaughter]───red_horse'
@.6 = 'Conquest_[War]───white_horse'
do L=1 while @.L\==''; @@.L=@.L; end;
/*──────────────────────────────────────────────────────────────────────────────────────*/
_=word(q, 1);
end
do k=1 for #; _=word(#.?, k); @.k=@@._; end /*k*/;
/*──────────────────────────────────────────────────────────────────────────────────────*/
.pNext: procedure expose !.; parse arg n,i;
do k=nm by -1 for nm; kp=k+1
if !.k<!.kp then do; i=k; leave; end
end /*k*/ /* [↓] swap two array elements*/
parse value !.j !.i with !.i !.j /*swap two values in !. array.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
call .pAdd; do while .pNext(n, 0); call .pAdd; end /*while*/
end
return</lang>
<pre>
element 1 before sort: ---Four horsemen of the Apocalypse---
Line 1,537 ⟶ 1,534:
element 6 after sort: Pestilence [Slaughter]───red horse
Permutation sort took 21 permutations to find the sorted list.
</pre>
|