sorting a list and counting interchanges

Jordan Rastrick jrastrick at student.usyd.edu.au
Wed Apr 6 20:59:04 EDT 2005


Unless I'm mistaken, this doesnt quite work, because it switches the
parity of phase every time a comparison is made, rather than every time
a swap is made. So:

# <untested>
phase = 1
def mycmp(x,y):
   global phase
   c = cmp(x,y)
   if c > 0: # i.e. a swap will be performed in the sort
       phase = -phase
   return c




More information about the Python-list mailing list