The Full Counting Sort

  • + 0 comments

    In Python:

    def countSort(arr):
        d = {}
        arr_mid = len(arr)/2
        for index, a in enumerate(arr):
            k = int(a[0])
            v = "-" if index < arr_mid else a[1]
            if k in d.keys():
                d[k].append(v)
            else:
                d[k] = [v]
    
        r = ""
        for sk in sorted(d.keys()):
            r = " ".join([r, *d[sk]])
        print(r.strip())