Exchange Sorting CS-240 Dick Steflik
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
Exchange Sort 9572 Compare 9 to 5; 9 is greater than 5 so swap them
Exchange Sort Compare 9 to 7, 9 is greater than 7 so swap them
Exchange Sort Compare 9 to 2, 9 is greater than 2 so swap them
Exchange Sort 9572 Notice that 9 is where it belongs Start back at the first element...
Exchange Sort 9572 Compare 5 to 7, 5 is less than 7 so leave them alone
Exchange Sort 9572 Compare 7 to 2, 7 is greater than 2 so swap them
Exchange Sort 9572 Notice that 7 is now in the right place Start back at the first element
Exchange Sort 9572 Compare 5 to 2, 5 is grerater than 2 so swap them
Exchange Sort 9572 End of n-1 pass, sort is done.