3 ms·
I feel like bubble sort is simpler. repeat n times: for i = 1 to n-1: if a[i] > a[i+1]: swap(a[i], a[i+1]) It's true you have to add and s
by lacker 5y ago
I feel like bubble sort is simpler.
repeat n times:
for i = 1 to n-1:
if a[i] > a[i+1]:
swap(a[i], a[i+1])
It's true you have to add and subtract 1, but you only have one variable, and of course the rationale for why it works is far simpler.