Skip to content

Bubble sort

Put the smallest height first

  • Four heights sit in an array. The smallest should come first.
  • Compare each pair of neighbours. When the left one is larger, swap them.
  • That single comparison does not finish the list. The next pair is compared after it.

One pass over 160, 152, 171, 148: swap, keep, swap; 171 reaches the end but 148 is not first yet

Handout

Log in or create account

IGCSE, A-Level & AP