I have a given string array of date, the format is dd/mm/yyyy.
I want to sort the date by month and year in ascendingly with radix sort, but I have no idea how because in the end the it would sort based on the largest number of month
for example i have the following array:
16/04/2012
01/05/2013
01/02/2012
10/11/2012
01/12/2012
normally the result after the sort is:
01/02/2012 16/04/2012 01/05/2013 10/11/2012 01/12/2012
while what i want is:
01/02/2012 16/04/2012 10/11/2012 01/12/2012 01/05/2013
year 2012 first then 2013
i haven’t made the code yet because i don’t know how the algorithm works and i have to make with only 1 radix sort
Think of sorting the dates not on the representation you have, but on a separate sort key instead. For example, for the date 01/02/2012 create a sort key 20120201. Now that the digits are in the order from most to least significant, you can treat the sort keys as numbers and apply radix sort to them.
If you wish, you don’t have to explicitly create the sort keys, but then you’d have to modify the code that picks a digit for a round of radix sort to enforce proper order.