[Issue 8331] Problem with sort!(SwapStrategy.stable)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 1 09:00:50 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8331



--- Comment #1 from bearophile_hugs at eml.cc 2012-07-01 09:03:27 PDT ---
This little Python program gives the same output as the merge sort and
insertion sort (Python built-in sort is stable):


from itertools import imap
a = [45,8,94,23,30,61,99,48,49,92,32,1,71,45,6,65,54,34,37,7,64,80,9,23,33,30]
b =
[45,55,38,66,89,82,92,70,92,86,63,25,95,45,3,84,42,58,70,83,98,53,72,36,88,0]

def cmp(i, j):
    if b[i] * a[j] > b[j] * a[i]: return -1
    elif b[i] * a[j] < b[j] * a[i]: return 1
    return 0

print sorted(range(len(a)), cmp=cmp)


Outputs:
[11, 19, 22, 1, 4, 3, 24, 10, 18, 8, 17, 23, 20, 7, 5, 12, 15, 0, 13, 9, 6, 16,
21, 14, 2, 25]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list