Sorting Algorithms/Circle Sort: Difference between revisions
Content added Content deleted
(Added Julia language) |
m (→{{header|REXX}}: optimized a subroutine, altered capitalization, changed an output text, added templates for the output.) |
||
Line 980: | Line 980: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
circleSort: do while .circleSrt(1, arg(1), 0)\==0; end; return |
circleSort: do while .circleSrt(1, arg(1), 0)\==0; end; return |
||
make_array: #=words(x); do i=1 |
make_array: #=words(x); do i=1 for #; @.i=word(x, i); end; say arg(1) x; return |
||
make_list: y=@.1; do j=2 |
make_list: y=@.1; do j=2 for #-1; y=y @.j; end; say arg(1) y; return |
||
.swap: parse arg a,b; parse value @.a @.b with @.b @.a; swaps=swaps+1; return |
.swap: parse arg a,b; parse value @.a @.b with @.b @.a; swaps=swaps+1; return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
.circleSrt: procedure expose @.; parse arg |
.circleSrt: procedure expose @.; parse arg LO,HI,swaps /*obtain LO & HI arguments.*/ |
||
if |
if LO==HI then return swaps /*1 element? Done with sort.*/ |
||
high= |
high=HI; low=LO; mid=(HI-LO) % 2 /*assign some indices. */ |
||
/* [↓] sort a section of #'s*/ |
/* [↓] sort a section of #'s*/ |
||
do while |
do while LO<HI /*sort within a section. */ |
||
if @. |
if @.LO>@.HI then call .swap LO,HI /*are numbers out of order ? */ |
||
LO=LO+1; HI=HI-1 /*add to LO; shrink the HI. */ |
|||
end /*while |
end /*while*/ /*just process one section. */ |
||
_=hi+1 /*point to HI plus one. */ |
_=hi+1 /*point to HI plus one. */ |
||
if |
if LO==HI & @.LO>@._ then call .swap LO, _ /*numbers still out of order?*/ |
||
swaps=.circleSrt(low, low+mid, swaps) |
swaps=.circleSrt(low, low+mid, swaps) /*sort the lower section. */ |
||
swaps=.circleSrt(low+mid+1, high, swaps) |
swaps=.circleSrt(low+mid+1, high, swaps) /* " " higher " */ |
||
return swaps /*the section sorting is done*/</lang> |
return swaps /*the section sorting is done*/</lang> |
||
{{out|output|text= when using the default input:}} |
|||
<pre> |
<pre> |
||
before sort: 6 7 8 9 2 5 3 4 1 |
before sort: 6 7 8 9 2 5 3 4 1 |
||
after sort: 1 2 3 4 5 6 7 8 9 |
after sort: 1 2 3 4 5 6 7 8 9 |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> 2 3 3 5 5 1 1 7 7 6 6 4 4 0 0 </tt>}} |
|||
<pre> |
<pre> |
||
before sort: 2 3 3 5 5 1 1 7 7 6 6 4 4 0 0 |
before sort: 2 3 3 5 5 1 1 7 7 6 6 4 4 0 0 |
||
after sort: 0 0 1 1 2 3 3 4 4 5 5 6 6 7 7 |
after sort: 0 0 1 1 2 3 3 4 4 5 5 6 6 7 7 |
||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> 2 3 44 44 5.77 +1 -12345 -3 -3.9 1e7 9 </tt>}} |
|||
<pre> |
<pre> |
||
before sort: 2 3 44 44 5.77 +1 -12345 -3 -3.9 1e7 0 |
before sort: 2 3 44 44 5.77 +1 -12345 -3 -3.9 1e7 0 |
||
after sort: -12345 -3.9 -3 0 +1 2 3 5.77 44 44 1e7 |
|||
</pre> |
</pre> |
||
'''output''' when using the input of: <tt> assinine donkey bovine cattle canine dog corvine crow equine horse feline cat hircine goat leporine hare lupine wolf murine rodent piscine fish porcine pig ursine bear vulpine fox </tt> |
'''output''' when using the input of: <tt> assinine donkey bovine cattle canine dog corvine crow equine horse feline cat hircine goat leporine hare lupine wolf murine rodent piscine fish porcine pig ursine bear vulpine fox </tt> |