World's most popular travel blog for travel bloggers.

[Solved]: Min-max selection sort

, , No Comments
Problem Detail: 

Is there already modified version of selection sort that works like this pseudocode:

a // the array, index starts at 1 (not zero-based) n = len(a) for x in 1 to n   big = x    small = x   last = n-x+1   for y in x+1 to last     if a[big] < a[y] then big = y     if a[small] > a[y] then small = y   if big <> small      if small <> x then swap(a[small],a[x])     if big <> last then swap(a[big],a[last]) 

if there is such an algorithm, what is the name of it?

Asked By : Kokizzu

Answered By : FrankW

As the wikipedia article on selection sort states, this variant is called cocktail sort.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/28588

0 comments:

Post a Comment

Let us know your responses and feedback