'********************************************** '* Demonstration program of Bubble sorting * '* (about n*n comparisons used). * '* ------------------------------------------ * '* Reference: "A book on C by Al Kelley and * '* Ira Pohl, The Benjamin/Cummings Publishing * '* Company, Inc, 1984" [BIBLI 09]. * '* * '* Basic version by J-P Moreau. * '* (www.jpmoreau.fr) * '* ------------------------------------------ * '* SAMPLE RUN: * '* * '* Initial table A: * '* 7 3 66 3 -5 22 -77 2 36 -12 * '* * '* Sorted table A: * '* -77 -12 -5 2 3 3 7 22 36 66 * '* * '********************************************** 'Program Bubble_sort defint i-n MAX=1024 dim IA(MAX) n=10 IA(1)=7: IA(2)=3: IA(3)=66: IA(4)=3: IA(5)=-5 IA(6)=22: IA(7)=-77: IA(8)=2: IA(9)=36: IA(10)=-12 cls print print " Initial table A:" for i=1 to n print " ";IA(i); next print gosub 1000 'call Bubble(A,n) print " Sorted table A:" for i=1 to n print " ";IA(i); next print print END 'return ip,iq in ascending order 900 if ip>iq then itemp=ip ip=iq iq=itemp end if return 'Buuble sorting of integer array IA 1000 for i=1 to n for j=n to i+1 step -1 ip=IA(j-1) : iq=IA(j) gosub 900 'call Order(A(j-1), A(j)) IA(j-1)=ip : IA(j)=iq next j next i return 'end of file bubble.bas