Sorting algorithms/Insertion sort: Difference between revisions
Sorting algorithms/Insertion sort (view source)
Revision as of 20:05, 15 January 2011
, 13 years agomoved realbasic back to its own section; minor markup edits to rexx
m (moved realbasic back to its own section; minor markup edits to rexx) |
|||
Line 138:
=={{header|BASIC}}==
{{works with|QBasic}}
This version
<lang qbasic>DECLARE SUB InsertionSort (theList() AS INTEGER)
Line 174 ⟶ 175:
Sample output:
1486 ; 9488 ; 9894 ; 17479 ; 18989 ; 23119 ; 23233 ; 24927 ; 25386 ; 26689 ;
▲{{works with|REALbasic}}
<lang vb> Sub InsertionSort(theList() as Integer)▼
for insertionElementIndex as Integer = 1 to UBound(theList)▼
dim insertionElement as Integer = theList(insertionElementIndex)▼
dim j as Integer = insertionElementIndex - 1▼
while (j >= 0) and (insertionElement < theList(j))▼
theList(j + 1) = theList(j)▼
j = j - 1▼
wend▼
theList(j + 1) = insertionElement▼
next▼
End Sub</lang>▼
=={{header|BBC BASIC}}==
Line 963 ⟶ 951:
insertionsort(c(4, 65, 2, -31, 0, 99, 83, 782, 1)) # -31 0 1 2 4 65 83 99 782</lang>
=={{header|REALbasic}}==
▲ for insertionElementIndex as Integer = 1 to UBound(theList)
▲ dim insertionElement as Integer = theList(insertionElementIndex)
▲ dim j as Integer = insertionElementIndex - 1
▲ while (j >= 0) and (insertionElement < theList(j))
▲ theList(j + 1) = theList(j)
▲ j = j - 1
▲ wend
▲ theList(j + 1) = insertionElement
▲ next
=={{header|REXX}}==
<lang rexx>/*REXX program sorts an array using the insertion-sort method. */▼
▲/*REXX program sorts an array using the insertion-sort method. */
call gen@ /*generate array elements. */
Line 1,021 ⟶ 1,020:
say copies('─',80) /*show a seperator line. */
return</lang>
Output:
element 1 before sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element
element
element
element
element
element
element
element
────────────────────────────────────────────────────────────────────────────────▼
▲────────────────────────────────────────────────────────────────────────────────
element 1 after sort: ---Monday's Child Is Fair of Face (by Mother Goose)---
element
element
element
element
element
element
element
element
────────────────────────────────────────────────────────────────────────────────▼
▲────────────────────────────────────────────────────────────────────────────────
=={{header|Ruby}}==
|