Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if...

5
Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : www.2july- maths.co.uk 1. Compare items 1 and 2; swap them if necessary 2. Compare 2 and 3; swap if necessary; then 1 and 2 again; 3. Compare 3 and 4, then 2 and 3, then 1 and 2; 4. etc. This is an adaption of the Bubble sort, it sorts the sub list fully for each pass.

Transcript of Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali : 1.Compare items 1 and 2; swap them if...

Page 1: Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali :  1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.

Decision Maths 1

Sorting AlgorithmShuttle Sort

A V Ali : www.2july-maths.co.uk

1. Compare items 1 and 2; swap them if necessary

2. Compare 2 and 3; swap if necessary; then 1 and 2 again;

3. Compare 3 and 4, then 2 and 3, then 1 and 2;

4. etc.

This is an adaption of the Bubble sort, it sorts the sub list fully for each pass.

Page 2: Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali :  1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.

5 7 312

95

Shuttle Sort

5 7 312

95 No sort neededPass 1

Page 3: Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali :  1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.

Pass 2

5 7 312

95

5 5 312

97 No sort needed

Sort needed

Page 4: Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali :  1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.

Pass 5

5 5 312

97

5 5 312

97 Sort needed

5 5 12

3 97

5 5 12

7 93

5 3 12

7 95

Sort needed

Sort needed

Sort needed

Pass 4 No sort needed

Page 5: Decision Maths 1 Sorting Algorithm Shuttle Sort A V Ali :  1.Compare items 1 and 2; swap them if necessary 2.Compare 2 and 3; swap.

Pass 6

3 5 12

7 95 Sort needed

3 5 97 12

5 No sort needed

3 5 97 12

5 Sorted !!