Post on 13-Jan-2016
Bubble Sort18th December 2014
With Mrs Billinghurst
@SGS_Computing
Bubble Sort18th December 2014
Bubble Sort AlgorithmThis is an algorithm that takes random data in a list and sorts it in order by swapping individual items in a list.
2 30 16 22 4 10 96 25 3 13016 22 30 304 3010 9625 963 9614 2210 22 25 303 301 304 1610 16 3 251 253 221 223 161 163 101 103 41 41 31 2
Bubble Sort18th December 2014
Bubble Sort Algorithm
WHILE List is unsorted DO FOR n items in list DO IF n > n+1 THEN swap items END IF END FOREND WHILE
Bubble Sort18th December 2014
Bubble Sort Algorithm
Stepper Variables allow us to indicate which iteration we
are in, and also point to our current
place in the array
Bubble Sort18th December 2014
Bubble Sort Algorithm
This is a call to a user-defined sub-routine. This code will not actually function until we’ve
written the procedures!
Bubble Sort18th December 2014
Bubble Sort Algorithm
Bubble Sort18th December 2014
Bubble Sort Algorithm
Bubble Sort18th December 2014
Bubble Sort Algorithm
Bubble Sort18th December 2014
Bubble Sort Algorithm
Bubble Sort18th December 2014
Bubble Sort Algorithm
Bubble Sort18th December 2014
Bubble Sort Algorithm
Local variables mean that they are only seen within the Scope of our
SortData procedure
The while loop will keep returning to the start of
the array until all the items are sorted
The holder variable allows us to swap the
two items without clashes in the data
Each time an item doesn’t need to be swapped, sorted
increments by 1. If sorted = 9 then all data items must be
sorted
Bubble Sort18th December 2014
Bubble Sort Algorithm