Citation :
Swap Sort Swap sort is similar to bubble sort, although the first time through the list the first and second elements are compared (and swapped if necessary), then the 3rd and 4th elements are compared, etc. The second time through the list the first element is skipped and the second and third elements are compared, then the 4th and 5th, and so on... Swap Sort Given a list of elements L = ( e1 e2 ... en ) with length n. Do n/2 times: For each element ei where i is odd: If ei > ei+1 Then swap ei with ei+1 For each element ei where i is even: If ei > ei+1 Then swap ei with ei+1 The list is now sorted. This sorting algorithm is less intuitive than the bubble sort (it's not as obvious why after completion the list will be sorted).
|