Sorting algorithms/Gnome sort: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: removed superflous blanks, added comments to source code. -- ~~~) |
|||
Line 1,372: | Line 1,372: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
⚫ | |||
<lang rexx> |
|||
⚫ | |||
⚫ | |||
call show@ 'before sort' /*show "before" array elements.*/ |
|||
call |
call gnomeSort highItem /*invoke the infamous gnome sort.*/ |
||
call show@ ' |
call show@ ' after sort' /*show "after" array elements.*/ |
||
⚫ | |||
⚫ | |||
exit |
exit |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
k=2 |
|||
⚫ | |||
⚫ | |||
do j=3 while k<=n |
|||
⚫ | |||
km1=k-1 |
|||
⚫ | |||
⚫ | |||
end /*j*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return |
return |
||
⚫ | |||
gen@: @.= /*assign a default value (null). */ |
|||
⚫ | |||
⚫ | |||
@.1='---the seven virtues---' |
@.1='---the seven virtues---' |
||
@.2='=======================' |
@.2='=======================' |
||
Line 1,413: | Line 1,402: | ||
@.8='Prudence' |
@.8='Prudence' |
||
@.9='Temperance' |
@.9='Temperance' |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
do j=1 for highItem |
|||
⚫ | |||
end |
|||
⚫ | |||
return |
return |
||
⚫ | |||
</lang> |
|||
⚫ | |||
Output: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
say copies('─',60) /*show a seperator line. */ |
|||
⚫ | |||
'''output''' |
|||
⚫ | |||
element 1 before sort: ---the seven virtues--- |
element 1 before sort: ---the seven virtues--- |
||
element 2 before sort: ======================= |
element 2 before sort: ======================= |
||
Line 1,442: | Line 1,424: | ||
element 8 before sort: Prudence |
element 8 before sort: Prudence |
||
element 9 before sort: Temperance |
element 9 before sort: Temperance |
||
──────────────────────────────────────────────────────────── |
|||
──────────────────────────────────────────────────────────────────────────────── |
|||
element 1 after sort: ---the seven virtues--- |
element 1 after sort: ---the seven virtues--- |
||
element 2 after sort: ======================= |
element 2 after sort: ======================= |
||
Line 1,453: | Line 1,434: | ||
element 8 after sort: Prudence |
element 8 after sort: Prudence |
||
element 9 after sort: Temperance |
element 9 after sort: Temperance |
||
──────────────────────────────────────────────────────────── |
|||
──────────────────────────────────────────────────────────────────────────────── |
|||
</pre> |
</pre> |
||