Home
Categories
EXPLORE
True Crime
Comedy
Society & Culture
Business
Sports
TV & Film
Technology
About Us
Contact Us
Copyright
© 2024 PodJoint
00:00 / 00:00
Sign in

or

Don't have an account?
Sign up
Forgot password
https://is1-ssl.mzstatic.com/image/thumb/Podcasts115/v4/d2/01/2f/d2012f8d-2bba-b9b1-e0e7-14a686e6e019/mza_12162428384170880572.jpg/600x600bb.jpg
Jay's Commodore Podcast
Jay Versluis
16 episodes
9 months ago
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.
Show more...
Technology
RSS
All content for Jay's Commodore Podcast is the property of Jay Versluis and is served directly from their servers with no modification, redirects, or rehosting. The podcast is not affiliated with or endorsed by Podjoint in any way.
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.
Show more...
Technology
https://wpguru.co.uk/wp-content/uploads/2018/08/Commodore-Podcast-Icon.jpg
Sorting an Array on the Commodore 64
Jay's Commodore Podcast
6 minutes 46 seconds
7 years ago
Sorting an Array on the Commodore 64

In this episode I’ll demonstrate how to sort a numeric array on the Commodore 64. The same principle works for string arrays, and of course on all other Commodore BASIC computers.
The technique I’m using here is called Bubble Sort: in effect we’re comparing the first two items in the array, and if the left one is larger than the right one, the values are swapped around. This loop continues until all items in the array have been compared and sorted (hence the smallest items “bubble” to the front of the array, much like the smallest bubbles in a soda float to the top first).
Here’s the full code I’m building, including the lottery portion. The Bubble Sort code starts in line 200.
10 x=rnd(-ti)
20 for i=1 to 6
30 rn=int(rnd(1)*49)+1
40 for j=1 to i
50 if n(j)=rn then 30
60 next j
70 n(i)=rn
80 next i
100 print:gosub 200
110 for i=1 to 6
120 print n(i);
130 next
140 print
199 goto 20
200 rem bubble sort
210 for i=5 to 1 step -1
220 for j=1 to i
230 x=n(j):y=n(j+1)
240 if x>y then n(j)=y:n(j+1)=x
250 next:next
299 return
I’ve explained how to build the lottery generator in this code here: https://wpguru.co.uk/2018/03/how-to-generate-lottery-numbers-on-the-commodore-64/
Happy retro hacking!
Jay's Commodore Podcast
Join Jay Versluis for tips and tricks on programming in BASIC and Assembly on vintage Commodore systems.