Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
m (moved realbasic back to its own section; minor markup edits to rexx) |
|||
Line 138: | Line 138: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
⚫ | |||
{{works with|QBasic}} |
{{works with|QBasic}} |
||
This version |
This version should work on any BASIC that can accept arrays as function arguments. |
||
<lang qbasic>DECLARE SUB InsertionSort (theList() AS INTEGER) |
<lang qbasic>DECLARE SUB InsertionSort (theList() AS INTEGER) |
||
Line 174: | Line 175: | ||
Sample output: |
Sample output: |
||
1486 ; 9488 ; 9894 ; 17479 ; 18989 ; 23119 ; 23233 ; 24927 ; 25386 ; 26689 ; |
1486 ; 9488 ; 9894 ; 17479 ; 18989 ; 23119 ; 23233 ; 24927 ; 25386 ; 26689 ; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
Line 963: | Line 951: | ||
insertionsort(c(4, 65, 2, -31, 0, 99, 83, 782, 1)) # -31 0 1 2 4 65 83 99 782</lang> |
insertionsort(c(4, 65, 2, -31, 0, 99, 83, 782, 1)) # -31 0 1 2 4 65 83 99 782</lang> |
||
=={{header|REALbasic}}== |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
⚫ | |||
<lang rexx> |
|||
⚫ | |||
call gen@ /*generate array elements. */ |
call gen@ /*generate array elements. */ |
||
Line 1,021: | Line 1,020: | ||
say copies('─',80) /*show a seperator line. */ |
say copies('─',80) /*show a seperator line. */ |
||
return |
return</lang> |
||
</lang> |
|||
Output: |
Output: |
||
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)--- |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
element |
element 2 before sort: Monday's child is fair of face; |
||
element |
element 3 before sort: Tuesday's child is full of grace; |
||
element |
element 4 before sort: Wednesday's child is full of woe; |
||
element |
element 5 before sort: Thursday's child has far to go; |
||
element |
element 6 before sort: Friday's child is loving and giving; |
||
element |
element 7 before sort: Saturday's child works hard for a living; |
||
element |
element 8 before sort: But the child that is born on the Sabbath day |
||
element |
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 |
element 2 after sort: But the child that is born on the Sabbath day |
||
element |
element 3 after sort: Friday's child is loving and giving; |
||
element |
element 4 after sort: Is blithe and bonny, good and gay. |
||
element |
element 5 after sort: Monday's child is fair of face; |
||
element |
element 6 after sort: Saturday's child works hard for a living; |
||
element |
element 7 after sort: Thursday's child has far to go; |
||
element |
element 8 after sort: Tuesday's child is full of grace; |
||
element |
element 9 after sort: Wednesday's child is full of woe; |
||
⚫ | |||
element 9 after sort: Wednesday's child is full of woe; |
|||
⚫ | |||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |