Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created October 4, 2010 17:41
Show Gist options
  • Select an option

  • Save thinkphp/610123 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/610123 to your computer and use it in GitHub Desktop.
Algorithm B (Bubble Sort). Records R(1),...,R(N) are rearranged
in place; after sorting is complete their keys will be in
order, K(1)<=K(2)<= ...<=K(N).
1. Set BOUND <-- N (BOUND is the highest index for which
the record is known to be in its final position).
2. Set t <-- 0, Perform step 3 for j=1,2,...,BOUND - 1, and then go to step 4
3. If K(j) > K(j+1) , interchange R(j) <--> R(j+1) and set t <-- j.
4. If t = 0 , the algorithm terminates, otherwise set BOUND <-- t
and return to step 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment