Created
March 7, 2020 20:26
-
-
Save cdyk/2e22aa7fd761121f085b5e25b6ff8767 to your computer and use it in GitHub Desktop.
Radix sort starting with least significant bit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
def radixSortLsb(a): | |
for b in range(0,10): | |
a = list(chain(filter(lambda x: ((x>>b)&1) == 0, a), | |
filter(lambda x: ((x>>b)&1) != 0, a))) | |
return a | |
ai =[503, 87, 512, 61, 908, 170, 897, 275, 653, 426, 154, 509, 612, 677, 765, 703] | |
radixSortLsb(ai) | |
# yields | |
# [61, 87, 154, 170, 275, 426, 503, 509, 512, 612, 653, 677, 703, 765, 897, 908] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment