Sorting algorithms/Bubble sort: Difference between revisions
Sorting algorithms/Bubble sort in Quite BASIC
(Added Chipmunk Basic) |
(Sorting algorithms/Bubble sort in Quite BASIC) |
||
Line 1,902:
NEXT I
PRINT
END</syntaxhighlight>▼
END▼
▲</syntaxhighlight>
{{out}} (2 samples)
<pre>Before: 91 97 3 62 17 48 89 7 2 66
After: 21 22 27 44 45 54 60 64 84 93</pre>▼
==={{header|Quite BASIC}}===
Before: 22 60 45 44 54 93 84 27 21 64▼
<syntaxhighlight lang="qbasic">100 rem Sorting algorithms/Bubble sort
▲After: 21 22 27 44 45 54 60 64 84 93
110 LET n = 10
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
▲200 END
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
410 RETURN</syntaxhighlight>▼
{{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}}===
Line 1,950 ⟶ 1,982:
NEXT I
PRINT
END</syntaxhighlight>
▲</syntaxhighlight>
{{out}} (2 samples)
After: 4 9 10 15 21 24 27 80 93 96</pre>▼
▲After: 4 9 10 15 21 24 27 80 93 96
==={{header|REALbasic}}===
|