sorting a list and counting interchanges

Peter Nuttall p.s.nuttall at durham.ac.uk
Thu Apr 7 07:01:49 EDT 2005


On Wed, Apr 06, 2005 at 03:30:41PM -0700, RickMuller wrote:
> I have to sort a list, but in addition to the sorting, I need to
> compute a phase factor that is +1 if there is an even number of
> interchanges in the sort, and -1 if there is an odd number of
> interchanges.
>

<snip>

I would just write a quicksort and have a counter in the swap function.
A cunning way to do it would be to multiply the counter by -1 for each
swap. if you want I can write what I had in mind. Wikipedia has a good
article of quicksort.

Pete



More information about the Python-list mailing list