i have a list 1 column and 100 rows each with a number
the number on each row may not be unique
i need to output the unique list of numbers sorted according to their rank , which is less if the number of its repetitions is more. least ranked number i.e 1 is on the top
now here is how i am planning to solve this problem
first i want to define an array of the structure would be like this
struct abc[100]
{
int number
int occurrence = 1;
}
now i want to go through the list for each row and check if the number exist in the array of structure or not. if it does not i want to store the number in a abc[row].number however if the number exists in the array of structure i want to increment the occurrence of that particular record.
at the end i would get a array of structure filled with each unique number and number of time it occurs together as records.
Is this style of programming a good way ? defining structures and moving through them is looking a tedious job to me can you suggest me a better way ? I’m a beginner programmer please feel free to give me any sort of advice
Here is an example that returns a Map of item frequencies. The method is generic and will therefore work for any type of item, not just
Integer. I’m returning aSortedMap(TreeMapimplementation) and hence the function runs with complexity O(n log n). However, I could have opted for aHashMapimplementation, reducing the complexity to O(n) (as insert performance forHashMapis O(1)).