Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(Added Chipmunk Basic) |
(Sorting algorithms/Bubble sort in Quite BASIC) |
||
Line 1,902: | Line 1,902: | ||
NEXT I |
NEXT I |
||
PRINT |
PRINT |
||
⚫ | |||
⚫ | |||
⚫ | |||
{{out}} (2 samples) |
{{out}} (2 samples) |
||
<pre>Before: 91 97 3 62 17 48 89 7 2 66 |
|||
<pre> |
|||
After: 2 3 7 17 48 62 66 89 91 97</pre> |
|||
<pre>Before: 22 60 45 44 54 93 84 27 21 64 |
|||
⚫ | |||
</pre> |
|||
<pre> |
|||
==={{header|Quite BASIC}}=== |
|||
⚫ | |||
<syntaxhighlight lang="qbasic">100 rem Sorting algorithms/Bubble sort |
|||
⚫ | |||
110 LET n = 10 |
|||
</pre> |
|||
120 array a |
|||
130 GOSUB 310 |
|||
140 PRINT "unsort "; |
|||
150 GOSUB 360 |
|||
160 rem Sort the array |
|||
170 GOSUB 210 |
|||
180 PRINT " sort "; |
|||
190 GOSUB 360 |
|||
⚫ | |||
210 rem Bubble sort the list A of length N |
|||
220 FOR i = 1 TO n-1 |
|||
230 FOR j = 1 TO n-i |
|||
240 IF a[j] <= a[j+1] THEN GOTO 280 |
|||
250 LET x = a[j] |
|||
260 LET a[j] = a[j+1] |
|||
270 LET a[j+1] = x |
|||
280 NEXT j |
|||
290 NEXT i |
|||
300 RETURN |
|||
310 rem Create a RANDOM list of N integers |
|||
320 FOR i = 1 TO n |
|||
330 LET a[i] = FLOOR(RAND(100)) |
|||
340 NEXT i |
|||
350 RETURN |
|||
360 rem Print the list a |
|||
370 FOR i = 1 TO n |
|||
380 PRINT a[i];" "; |
|||
390 NEXT i |
|||
400 PRINT |
|||
⚫ | |||
{{out}} |
|||
<pre>unsort 19 78 39 54 63 68 66 52 94 2 |
|||
sort 2 19 39 52 54 63 66 68 78 94 </pre> |
|||
==={{header|RapidQ}}=== |
==={{header|RapidQ}}=== |
||
Line 1,950: | Line 1,982: | ||
NEXT I |
NEXT I |
||
PRINT |
PRINT |
||
END</syntaxhighlight> |
|||
END |
|||
⚫ | |||
{{out}} (2 samples) |
{{out}} (2 samples) |
||
⚫ | |||
<pre> |
|||
After: 19 33 34 44 48 57 62 71 73 82</pre> |
|||
<pre>Before: 4 15 96 93 27 24 9 80 10 21 |
|||
⚫ | |||
</pre> |
|||
<pre> |
|||
Before: 4 15 96 93 27 24 9 80 10 21 |
|||
⚫ | |||
</pre> |
|||
==={{header|REALbasic}}=== |
==={{header|REALbasic}}=== |