How to resolve the algorithm JortSort step by step in the REXX programming language
How to resolve the algorithm JortSort step by step in the REXX programming language
Table of Contents
Problem Statement
JortSort is a sorting tool set that makes the user do the work and guarantees efficiency because you don't have to sort ever again. It was originally presented by Jenn "Moneydollars" Schiffer at the prestigious JSConf.
JortSort is a function that takes a single array of comparable objects as its argument. It then sorts the array in ascending order and compares the sorted array to the originally provided array. If the arrays match (i.e. the original array was already sorted), the function returns true. If the arrays do not match (i.e. the original array was not sorted), the function returns false.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm JortSort step by step in the REXX programming language
Source code in the rexx programming language
/*REXX program verifies that an array is sorted using a jortSort algorithm. */
parse arg $ /*obtain the list of numbers from C.L. */
if $='' then $=1 2 4 3 /*Not specified? Then use the default.*/
say 'array items=' space($) /*display the list to the terminal. */
if jortSort($) then say 'The array is sorted.'
else say "The array isn't sorted."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose @.; h=@.0 /*exchange sort.*/
do while h>1; h=h%2
do i=1 for @.0-h; j=i; k=h+i
do while @.k<@.j; t=@.j; @.j=@.k; @.k=t
if h>=j then leave; j=j-h; k=k-h
end /*while @.k<@.j*/
end /*i*/
end /*while h>1*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
jortSort: parse arg x; @.0=words(x) /*assign # items in list. */
do j=1 for @.0; !.j=word(x,j); @.j=!.j /*save a copy of original.*/
end /*j*/
call eSort /*sort with exchange sort.*/
do k=1 for @.0
if !.k\==@.k then return 0 /*the array isn't sorted. */
end /*k*/
return 1 /*the array is sorted. */
/*REXX program verifies that an array is sorted using a jortSort algorithm. */
parse arg $ /*obtain the list of numbers from C.L. */
if $='' then $=1 2 4 3 /*Not specified? Then use the default.*/
say 'array items=' space($) /*display the list to the terminal. */
if jortSort($) then say 'The array is sorted.'
else say "The array isn't sorted."
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
jortSort: parse arg x
p=word(x,1)
do j=2 to words(x); _=word(x,j)
if _
p=_
end /*j*/
return 1 /*array is sorted.*/
You may also check:How to resolve the algorithm Caesar cipher step by step in the Perl programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Digital root step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Jacobi symbol step by step in the Go programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Tcl programming language