Download presentation
Presentation is loading. Please wait.
1
Exchange Sorting CS-240 Dick Steflik
2
Exchange Sort Strategy Make n-1 compares of adjacent items, swapping when needed Do this n-1 times with one less compare on each pass
3
Exchange Sort 9572 Compare 9 to 5; 9 is greater than 5 so swap them
4
Exchange Sort 9 5 72 Compare 9 to 7, 9 is greater than 7 so swap them
5
Exchange Sort 9 5 7 2 Compare 9 to 2, 9 is greater than 2 so swap them
6
Exchange Sort 9572 Notice that 9 is where it belongs Start back at the first element...
7
Exchange Sort 9572 Compare 5 to 7, 5 is less than 7 so leave them alone
8
Exchange Sort 9572 Compare 7 to 2, 7 is greater than 2 so swap them
9
Exchange Sort 9572 Notice that 7 is now in the right place Start back at the first element
10
Exchange Sort 9572 Compare 5 to 2, 5 is grerater than 2 so swap them
11
Exchange Sort 9572 End of n-1 pass, sort is done.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.