{ repeat the following steps until the list is sorted
put 1 into i
repeat while i < N
if A[i] > A[i+1]
then swap
A[i], A[i+1]
end if
add 1 to i
end repeat
end repeat
}end bubblesort
The bubble
sort algorithm:
Compare adjacent
elements. If the first is greater than the second, swap them.
Do this for each pair of
adjacent elements, starting with the first two and ending with the last
two. At this point the last element should be the greatest.
Repeat the steps for all
elements except the last one.
Continue for one
less element each time, until there are no more pairs to compare.