C
C#14mo ago
avoidenz

I'm having trouble understanding Bubble Sort.

So the whole schtick about a bubble algorithm is that it compares a number with the number next to it, and then sorts it based on the value of the numbers. So if an array were to look like this: int[] numbers = { 9, 7 }; It would compare 9 to 7, see that 9 is bigger than 7 and switch them. In my example the code should go like this if i understand it correctly: int i = 0 and the length of the array - 1 equals 6. So i then becomes 1 and the for loop is started. int j = 0 too and the length of the array - (1 + 1 (which is i)) equals 5. int j becomes 1 and the the for loop is started. Now here is where you lose me with this one. What is numbers[ j ]? I think i missed something about arrays i should know because i'm confused on how this ACTUALLY works. I understand the procedure but not the code. Ples help
No description
1 Reply
avoidenz
avoidenzOP14mo ago
I lowkey understood it as i was writing about me not understanding it. L M A O
Want results from more Discord servers?
Add your server