Frequency sort of a given array