We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My program has to store the words in a text and count the most used ones; this part of the program works perfectly and I have a String[] tracking the unuque words and a int[] that tracks how many times the word was used. They work togheder as if
String[] usedWords={"hi" ; "acrasial" };
int[] timesUsed={12 ; 1};
to express that hi was used 12 times ecc...
now to sort from the most used to the least used I convert the two arrays into a table, and then use table.sortReverse() . It doesn't work because the int is treated as a String, so the order would be 990-90-890-84-8-7700 ecc.
So I need to order an array of Strings and one of ints in the same way, but how?
Answers
An
IntDict
perhapshttp://forum.processing.org/two/discussion/13044/creating-a-rank-list-by-sorting-an-array/p1
or a Data class maybe
http://stackoverflow.com/questions/33160079/creating-a-rank-list-by-sorting-an-array
nice it was perfect! Is there a way to sort them by 2 different criterias? So that the ones that are used an equal number of times are also sorted Alphabetically?
Sure implement the algorithm in the class it self. just do something if ints are equals like this:
For a more complex stuff you can use
comparator
here an old example:Apparently IntDict's sortValues() & sortValuesReverse() already apply alphabetic order for equal values:
yes I just noticed that. Thank everybody