Bubble Sort: Code
for i := 1 to n-1 do
Switch := False;
for j := 1 to n-i do
if L[j] > L[j+1] then
Temp = L[j];
L[j] := L[j+1];
L[j+1] := Temp;
Switch := True;
endif
endfor
if Not Switch then break;
endfor
Worst case n-1 iterations
Fixed n-i iterations
Previous slide
Next slide
Back to first slide
View graphic version