Log In  


Bubble sort Algorithm example

Cart #tiyudezuwo-0 | 2022-08-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

Hi everyone!
First experiment with pico-8, visualising the bubble sort algorithm steps, for the array {3,10,5,7,2,13,1}.

2


Curious as to why Step 4 repeats itself (I've never used this particular algorithm).


@2bitchuck
It's called "bubble sort" because it's as if the lower values are floating to the top (or rather, left). The steps are as follows: 1. compare 3 and 10, 3 is less so no work. 2. compare 10 and 5, 5 is less so move it left until something lower (the 3). 3. compare 10 and 7, 7 is less so move it. 4. compare 10 and 2, 2 is less so move it (all the way over since it's lower than everything up to that point). 5. compare 10 and 13, 10 is less so no work to do. 6. compare 13 and 1, 1 is less so move it.


Hi @2bitchuck, thank you for your comment, the fixed version follows:

Cart #tiyudezuwo-3 | 2022-08-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA



[Please log in to post a comment]