Sorting algorithms/Bubble sort: Difference between revisions

no edit summary
No edit summary
Line 548:
<pre> AABBBBCDDEEFILLNNNORRRUUU</pre>
 
==={{header|BASIC256}}===
{{works with|BASIC256 }}
<lang basic256>
Line 584:
</pre>
 
==={{header|BBC BASIC}}===
The Bubble sort is very inefficient for 99% of cases. This routine uses a couple of 'tricks' to try and mitigate the inefficiency to a limited extent. Note that the array index is assumed to start at zero.
<lang bbcbasic> DIM test(9)
Line 612:
-31 0 1 2 2 4 65 83 99 782
</pre>
 
==={{header|IS-BASIC}}===
<lang IS-BASIC>
100 PROGRAM "BubblSrt.bas"
110 RANDOMIZE
120 LET N=20 ! Number of elements
130 NUMERIC ARRAY(1 TO N)
140 CALL INIT(ARRAY)
150 CALL WRITE(ARRAY)
160 CALL BUBBLESORT(ARRAY)
170 CALL WRITE(ARRAY)
180 DEF INIT(REF A)
190 FOR I=LBOUND(A) TO UBOUND(A)
200 LET A(I)=RND(N)+1
210 NEXT
220 END DEF
230 DEF WRITE(REF A)
240 FOR I=LBOUND(A) TO UBOUND(A)
250 PRINT A(I);
260 NEXT
270 PRINT
280 END DEF
290 DEF BUBBLESORT(REF A)
300 DO
310 LET CH=0
320 FOR I=LBOUND(A) TO UBOUND(A)-1
330 IF A(I)>A(I+1) THEN LET T=A(I):LET A(I)=A(I+1):LET A(I+1)=T:LET CH=1
340 NEXT
350 LOOP WHILE CH
360 END DEF</lang>
 
=={{header|C}}==
Anonymous user