Jump to content

Sorting algorithms/Bubble sort: Difference between revisions

Added ZX81 BASIC
(Added ZX81 BASIC)
Line 516:
NEXT
LOOP WHILE(NOT changed)</lang>
 
==={{header|Sinclair ZX81 BASIC}}===
Works with the 1k RAM model. For simplicity, and to make it easy to animate the sort as it is going on, this implementation sorts a string of eight-bit unsigned integers which can be treated as character codes; it could easily be amended to sort an array of numbers or an array of strings, but the array would need to be dimensioned at the start.
<lang basic> 10 LET S$="FIRE BURN AND CAULDRON BUBBLE"
20 PRINT S$
30 LET L=LEN S$-1
40 LET C=0
50 FOR I=1 TO L
60 IF S$(I)<=S$(I+1) THEN GOTO 120
70 LET T$=S$(I)
80 LET S$(I)=S$(I+1)
90 LET S$(I+1)=T$
100 PRINT AT 0,I-1;S$(I TO I+1)
110 LET C=1
120 NEXT I
130 LET L=L-1
140 IF C THEN GOTO 40</lang>
{{out}}
<pre> AABBBBCDDEEFILLNNNORRRUUU</pre>
 
=={{header|BASIC256}}==
519

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.