Mike Yearwood
Toronto, Ontario, Canada
Yes, but the source array is in very special case. Basically, the same result is obtained with:
for i = 1 to n
result[i]=i
endfor
I mean: the algorithm doesn't sort the source array. It's only a complicated way of doing something very simple... :)
Vlad
>Hey Paul.
>
>source[1]=10
>source[2]=5
>source[3]=8
>source[4]=1
>source[5]=9
>source[6]=2
>source[7]=6
>source[8]=7
>source[9]=3
>source[10]=4
>
>for i=1 to 10
> sorted[source[i]] = source[i]
>endfor
>
>so sorted[10] becomes the value of source[1] and sorted[5] gets the value of source[2] etc.
>
>What is amazing about this branch of this topic is the semantics. The code takes an unsorted list of numbers and produced a sorted list of numbers. It does this with only one pass through the source list. Its not possible to argue that this is not the fastest possible sort (unless your a lawyer).
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement