--- title: "Bubble Sort" id: 77879 type: "computer_media" slug: "bubble-sort" url: "http://localhost/computer_media/bubble-sort/" markdown_url: "http://localhost/computer_media/bubble-sort.md" published_at: "2026-11-19T15:04:03+00:00" modified_at: "2026-11-19T15:04:03+00:00" featured_image: url: "http://localhost/wp-content/uploads/2026/11/bubble-sort-1.png" excerpt: "A ZX80 demonstration of the bubble sort: it prints ten random numbers, sorts them into ascending order and prints them again." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "ZX80" slug: "zx80" taxonomy: "post_tag" url: "http://localhost/tag/zx80/" model: - name: "Sinclair ZX80" slug: "zx80" taxonomy: "model" url: "http://localhost/model/zx80/" indiv: - name: "Robert Schlesinger" slug: "robert-schlesinger" taxonomy: "indiv" url: "http://localhost/indiv/robert-schlesinger/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_type: "Program" programmers: - name: "Robert Schlesinger" slug: "robert-schlesinger" taxonomy: "indiv" url: "http://localhost/indiv/robert-schlesinger/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Bubble%20Sort%20%281981%29%28Schlesinger%2C%20Robert%29%28ZX80%29%28US%29%28Program%29.zip" mediadate: "1981" images: - url: "http://localhost/wp-content/uploads/2026/11/bubble-sort-1.png" - url: "http://localhost/wp-content/uploads/2026/11/bubble-sort-2.png" article_media: - id: 19228 title: "Bubble Sort Routine" type: "article" url: "http://localhost/article/bubble-sort-routine/" related_content: - id: 19241 title: "Syns of Omission" type: "article" url: "http://localhost/article/syns-of-omission/" media_type_tags: "Demo" license: false --- # Bubble Sort A short demonstration of the bubble sort for the 1K ZX80. Lines 1 to 50 fill an array with random numbers from 1 to 100. The program prints ten of them on one line, sorts them into ascending order with the routine that starts at line 200, then prints the sorted numbers underneath and stops. RUN again for a new set. The sort routine can be used on its own in your programs. The article suggests sorting words the same way by coding the letters as the numbers 1 to 26. Line 30 fills eleven elements, A(0) to A(10), but only the first ten are printed and sorted. Syntax left the author’s name off the article; the February 1981 issue credited Robert J. Schlesinger of Van Nuys, CA. Published in Syntax January 1981 ([Bubble Sort Routine](https://timexsinclair.com/article/bubble-sort-routine/)). ## Source Code ``` 1 REM * SET UP DIM ARRAY 10 DIM A(10) 30 FOR R=0 TO 10 43 LET S=RND(100) 45 LET A(R)=S 50 NEXT R 100 REM * PRINT OUT ROUTINE 105 LET P=0 107 LET X=0 110 PRINT A(X);" "; 115 LET X=X+1 120 IF X=10 THEN GO TO 150 130 IF X<10 THEN GO TO 110 150 LET P=P+1 160 IF P=2 THEN GO TO 300 190 REM **** BUBBLE SORT ROUTINE 200 FOR I=0 TO 10 210 LET J=9 220 IF A(J-1)I THEN GO TO 220 280 NEXT I 290 GO TO 107 300 STOP ```