<-- Previous || Up || Next -->

Sort Characters By Frequency Function
Character Arrays Class

Public Function SortCharactersByFrequency( _
    ByVal vValue As Variant _
    ) As Variant

Sorts the characters in a string based upon the descending frequency of those characters.
Result string will contain all of the characters from string vValue, NOT just the unique ones.
The sort is stable so that if characters have the same frequency, then they are listed in the same order in which they appeared within the input string.

Examples:
    SortCharactersByFrequency("DCCBBBAA") = "BBBCCAAD"
    SortCharactersByFrequency("332211") = "123"
See also:
    SortCharacters Function
    SortCharactersBinary Function
vValue: String containing the characters which are to be sorted by their descending frequency within that string. Function returns Null if vValue is Null or cannot be fixed up to a String.

Algotithm: This function sorts through distribution counting.
Note: Function uses the ASCII value of characters to determine if they match, which is in effect the same as using Binary comparisons.
Note: Function currently only works for characters whose ASCII value is between 0 and 255, so it does NOT support UNICODE.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.