Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed some comments, variable names, and some alignments.)
m (→‎{{header|REXX}}: shorten a long literal by one byte, changed a variable name, made a variable global.)
Line 1,730: Line 1,730:
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
gen@: @.= /*assign default value to array. */
gen@: @.= /*assign default value to array. */
@.1 = "---Monday's Child Is Fair of Face (by Mother Goose)---"
@.1 = "---Monday's Child Is Fair of Face (by Mother Goose)---"
@.2 = "Monday's child is fair of face;"
@.2 = "Monday's child is fair of face;"
@.3 = "Tuesday's child is full of grace;"
@.3 = "Tuesday's child is full of grace;"
Line 1,741: Line 1,741:
do #=1 while @.# \=='' /*find how many entries in array.*/
do #=1 while @.# \=='' /*find how many entries in array.*/
end /*short and sweet DO loop, eh? */
end /*short and sweet DO loop, eh? */
#=#-1 /*because of DO, adjust highItem.*/
@.0=#-1 /*because of DO, adjust high item*/
return
return
/*──────────────────────────────────INSERTIONSORT subroutine────────────*/
/*──────────────────────────────────INSERTIONSORT subroutine────────────*/
insertionSort: procedure expose @.; parse arg highItem
insertionSort: procedure expose @.
do i=2 to highItem; value=@.i
do i=2 to @.0
do j=i-1 by -1 while j\==0 & @.j>value
value=@.i; do j=i-1 by -1 while j\==0 & @.j>value
jp=j+1; @.jp=@.j
jp=j+1; @.jp=@.j
end /*j*/
end /*j*/
Line 1,762: Line 1,762:
{{out}}
{{out}}
<pre>
<pre>
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element 2 before sort: Monday's child is fair of face;
element 2 before sort: Monday's child is fair of face;
element 3 before sort: Tuesday's child is full of grace;
element 3 before sort: Tuesday's child is full of grace;
Line 1,772: Line 1,772:
element 9 before sort: Is blithe and bonny, good and gay.
element 9 before sort: Is blithe and bonny, good and gay.
───────────────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────────────
element 1 after sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element 1 after sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element 2 after sort: But the child that is born on the Sabbath day
element 2 after sort: But the child that is born on the Sabbath day
element 3 after sort: Friday's child is loving and giving;
element 3 after sort: Friday's child is loving and giving;