I have created a program that takes a list of phrases and then filters it to produce a second list containing only the unique words found in those phrases.
At the moment I am using a split string command to divide the phrases into an array of words but how can i sort that array so that the most frequently occurring words come first? i.e. sort by mode
Directly: you can't, BM has no priority sort with counting support.
Indirectly: Make an own compare function and use TList.
In the compare function, you cast the 2 objects to your own "container" class for the unique words. That container class has a field "count:int"
Whenever you find containerClass(a) == containerClass(b) (or how you call the 2 :object instances in the compare function), you raise the count of a and return 0.
when they are not equal, you return containerClass(a).count - containerClass(b).count
Thanks for the reply. Unfortunately I don't really understand what you mean. Do I need to create a type for unique words?
Thanks!
If i understand correctly you could perhaps use a tmap to store all the words and the value field you insert a counter that goes up if the word already is in the map.
You might want make a type that has a counter in it and has a compare method so it the map will sort correctly
You need a histogram, I guess?