How to resolve the algorithm Sorting Algorithms/Circle Sort step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sorting Algorithms/Circle Sort step by step in the Quackery programming language
Table of Contents
Problem Statement
Sort an array of integers (of any convenient size) into ascending order using Circlesort. In short, compare the first element to the last element, then the second element to the second last element, etc. Then split the array in two and recurse until there is only one single element in the array, like this: Repeat this procedure until quiescence (i.e. until there are no swaps). Show both the initial, unsorted list and the final sorted list. (Intermediate steps during sorting are optional.) Optimizations (like doing 0.5 log2(n) iterations and then continue with an Insertion sort) are optional. Pseudo code:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sorting Algorithms/Circle Sort step by step in the Quackery programming language
Source code in the quackery programming language
[ dup size 2 < iff
[ drop true ] done
true swap
dup [] != if
[ behead swap witheach
[ tuck > if
[ dip not
conclude ] ] ]
drop ] is sorted ( [ --> b )
[ behead swap witheach
[ 2dup < iff
nip else drop ] ] is largest ( [ --> n )
[ dup largest 1+
over size
dup 1
[ 2dup > while
1 << again ]
nip swap -
dup dip [ of join ]
swap ] is pad ( [ --> n [ )
[ swap dup if
[ negate split drop ] ] is unpad ( n [ --> [ )
[ dup size times
[ i i^ > not iff
conclude done
dup i peek
over i^ peek
2dup < iff
[ rot i poke
i^ poke ]
else 2drop ] ] is reorder ( [ --> [ )
[ pad
[ [ dup sorted if done
reorder
dup size 2 / split
recurse swap
recurse swap join ]
dup sorted until ]
unpad ] is circlesort ( [ --> [ )
$ "bababadalgharaghtakamminarronnkonnbronntonnerronntuonnthunntrovarrhounawnskawntoohoohoordenenthurnuk"
dup echo$ cr
circlesort echo$ cr
You may also check:How to resolve the algorithm Binary digits step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Brace expansion step by step in the REXX programming language
You may also check:How to resolve the algorithm Null object step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Executable library step by step in the Python programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the Factor programming language