# "ZX Spectrum Next BASIC - Bubble Sort"

I managed to code a bubble sort algorithm on the ZX Spectrum Next (running at 28Mhz) which has turned out to be quite a fun exercise (I've spent way too much time playing with it).

It generates an array of 20 random numbers from -50 to 49 (this could be any range of numbers) and then sorts them in ascending order. I guess my next challenge would be to sort them in descending order. It takes longer to sort them as I am printing the results each time a change is made and it takes about 3 to 5 seconds to sort the numbers without.

I'm planning to use this in the future as I have at least one idea for it, but it could be mostly used for high score tables. Feel free to use the code.

5 RUN AT 3: RANDOMIZE: BORDER 7: CLS
10 LET c=20: DIM a(c)
20 FOR b=1 TO c
30 LET %z= %(RND 100)-50
40 LET a(b)=%SGN {z}
50 PRINT AT b-10;a(b);
60 NEXT b
70 BORDER 2
100 LET swap=0
110 FOR b=1 TO c-1
120 IF a(b)>a(b+1) THEN LET pswap=a (b) : LET a(b)=a(b+1) : LET a(b+1)=pswap: LET swap=1
130 IF swap=1 THEN FOR z=1 TO c: PRINT AT z-1,0;a(z);" ";: NEXT z: GO TO 100
140 NEXT b
200 BORDER 4: PAUSE 0: BORDER 7 : CLS : GO TO 10