bubble sort 18 th december 2014 with mrs billinghurst @sgs_computing

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

Upload: bryce-leonard

Post on 13-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

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

Bubble Sort18th December 2014

With Mrs Billinghurst

@SGS_Computing

Page 2: Bubble Sort 18 th 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

Page 3: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

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

Page 4: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

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

Page 5: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

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!

Page 6: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 7: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 8: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 9: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 10: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 11: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm

Page 12: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

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

Page 13: Bubble Sort 18 th December 2014 With Mrs Billinghurst @SGS_Computing

Bubble Sort18th December 2014

Bubble Sort Algorithm