Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
Line 1,579: | Line 1,579: | ||
ary.insertionsort! |
ary.insertionsort! |
||
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</lang> |
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</lang> |
||
=={{header|Run BASIC}}== |
|||
<lang runbasic>dim insSort(100) |
|||
sortEnd = 0 |
|||
global inSort |
|||
global sortEnd |
|||
' -- insert some random numbers -- |
|||
for i = 1 to 20 |
|||
a = int(1000 * rnd(1)) |
|||
x = insertSort(a) |
|||
next i |
|||
' --- Print the Sorted Data ----- |
|||
print "End Sort:";sortEnd ' number sorted |
|||
for i = 1 to sortEnd |
|||
print i;" ";insSort(i) ' location and sorted data |
|||
next i |
|||
wait |
|||
function insertSort(x) ' Insert Sort Function |
|||
i = 1 |
|||
while x > insSort(i) and i <= sortEnd |
|||
i = i + 1 |
|||
wend |
|||
for j = sortEnd to i step -1 |
|||
insSort(j + 1) = insSort(j) |
|||
next j |
|||
insSort(i) = x |
|||
sortEnd = sortEnd + 1 |
|||
end function</lang><pre></pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |