function bubblesort (A : list[1..n]) for i from n downto 1 for j from 1 to i-1 if (A[j] > A[j+1]) then swap(A[j], A[j+1]) end if next next end function