Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bubble Sort 18 th December 2014 With Mrs

Similar presentations


Presentation on theme: "Bubble Sort 18 th December 2014 With Mrs"— Presentation transcript:

1 Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

2 Bubble Sort 18 th December 2014 Bubble Sort Algorithm This is an algorithm that takes random data in a list and sorts it in order by swapping individual items in a list. 2301622410962531 3016 22 30 4 10 96 25 96 3 1 4 22 10 22 25 30 3 1 4 16 10 16 3 25 1 3 22 1 3 16 1 3 10 1 3 4 1 4 1 3 1 2

3 Bubble Sort 18 th 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 FOR END WHILE

4 Bubble Sort 18 th 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

5 Bubble Sort 18 th 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!

6 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

7 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

8 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

9 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

10 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

11 Bubble Sort 18 th December 2014 Bubble Sort Algorithm

12 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

13 Bubble Sort 18 th December 2014 Bubble Sort Algorithm


Download ppt "Bubble Sort 18 th December 2014 With Mrs"

Similar presentations


Ads by Google