Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Sorting Animation Chapter 10. 2 Selection Sort Another way of sorting is the selection sort The main idea is to keep finding the smallest (and next.

Similar presentations


Presentation on theme: "1 Sorting Animation Chapter 10. 2 Selection Sort Another way of sorting is the selection sort The main idea is to keep finding the smallest (and next."— Presentation transcript:

1 1 Sorting Animation Chapter 10

2 2 Selection Sort Another way of sorting is the selection sort The main idea is to keep finding the smallest (and next smallest) items in the array And move them into correct position (swap)

3 3 Selection Sort 45 < smallest? F 45 smallest 0 small_pos 0 k data 01234567 453256921771817 0 n

4 4 Selection Sort 32 < smallest? T 45 smallest 0 small_pos 0 k data 01234567 453256921771817 1 n

5 5 Selection Sort 32 < smallest? T 32 smallest 1 small_pos 0 k data 01234567 453256921771817 1 n

6 6 Selection Sort 56 < smallest? F 32 smallest 1 small_pos 0 k data 01234567 453256921771817 2 n

7 7 Selection Sort 9 < smallest? T 32 smallest 1 small_pos 0 k data 01234567 453256921771817 3 n

8 8 Selection Sort 9 < smallest? T 9 smallest 3 small_pos 0 k data 01234567 453256921771817 3 n

9 9 Selection Sort 21 < smallest? F 9 smallest 3 small_pos 0 k data 01234567 453256921771817 4 n

10 10 Selection Sort 77 < smallest? F 9 smallest 3 small_pos 0 k data 01234567 453256921771817 5 n

11 11 Selection Sort 17 < smallest? F 9 smallest 3 small_pos 0 k data 01234567 453256921771817 6 n

12 12 Selection Sort—SWAP! 9 smallest 3 small_pos 0 k data 01234567 453256921771817 6 n Swap(data[k], data[small_pos]);

13 13 Selection Sort 32 < smallest? F 32 smallest 1 small_pos 1 k data 01234567 932564521771817 1 n

14 14 Selection Sort 32 < smallest? F 32 smallest 1 small_pos 1 k data 01234567 932564521771817 2 n

15 15 Selection Sort 45 < smallest? F 32 smallest 1 small_pos 1 k data 01234567 932564521771817 3 n

16 16 Selection Sort 21 < smallest? T 32 smallest 1 small_pos 1 k data 01234567 932564521771817 4 n

17 Selection Sort 21 < smallest? T 21 smallest 4 small_pos 1 k data 01234567 932564521771817 4 n

18 18 Selection Sort 77 < smallest? F 21 smallest 4 small_pos 1 k data 01234567 932564521771817 5 n

19 19 Selection Sort 18 < smallest? T 21 smallest 4 small_pos 1 k data 01234567 932564521771817 6 n

20 20 Selection Sort 18 < smallest? T 18 smallest 6 small_pos 1 k data 01234567 932564521771817 6 n

21 21 Selection Sort 17 < smallest? T 18 smallest 6 small_pos 1 k data 01234567 932564521771817 7 n

22 22 Selection Sort 17 < smallest? T 17 smallest 7 small_pos 1 k data 01234567 932564521771817 7 n

23 23 Selection Sort—SWAP! 17 smallest 7 small_pos 1 k data 01234567 932564521771817 7 n Swap(data[k], data[small_pos]);

24 24 Selection Sort—and so on 56 < smallest? F 56 smallest 2 small_pos 2 k data 01234567 917564521771832 2 n


Download ppt "1 Sorting Animation Chapter 10. 2 Selection Sort Another way of sorting is the selection sort The main idea is to keep finding the smallest (and next."

Similar presentations


Ads by Google