Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(Dialects of BASIC moved to the BASIC section.) |
(→{{header|BASIC}}: Clarified implementation of BASIC: QuickBASIC.) |
||
Line 1,141: | Line 1,141: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
⚫ | |||
{{trans|Java}} |
|||
Assume numbers are in a DIM of size "size" called "nums". |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
<syntaxhighlight lang="basic">0 GOSUB 7 : IC = I%(0) |
<syntaxhighlight lang="basic">0 GOSUB 7 : IC = I%(0) |
||
Line 1,615: | Line 1,598: | ||
Until hasChanged = #False |
Until hasChanged = #False |
||
EndProcedure</syntaxhighlight> |
EndProcedure</syntaxhighlight> |
||
==={{header|QuickBASIC}}=== |
|||
⚫ | |||
⚫ | |||
' Sorting algorithms/Bubble sort |
|||
' Prepare data |
|||
size = 10 |
|||
OPTION BASE 1 |
|||
DIM nums(size) |
|||
RANDOMIZE TIMER |
|||
PRINT "Before:"; |
|||
FOR I = 1 TO size |
|||
nums(I) = INT(RND * 100) |
|||
PRINT USING " ##"; nums(I); |
|||
NEXT I |
|||
PRINT |
|||
' Sort |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
'Display result |
|||
PRINT "After: "; |
|||
FOR I = 1 TO 10 |
|||
PRINT USING " ##"; nums(I); |
|||
NEXT I |
|||
PRINT |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} (2 samples) |
|||
<pre> |
|||
Before: 91 97 3 62 17 48 89 7 2 66 |
|||
After: 2 3 7 17 48 62 66 89 91 97 |
|||
</pre> |
|||
<pre> |
|||
Before: 22 60 45 44 54 93 84 27 21 64 |
|||
After: 21 22 27 44 45 54 60 64 84 93 |
|||
</pre> |
|||
==={{header|REALbasic}}=== |
==={{header|REALbasic}}=== |