Page 1 of 1

How to calculate biggest number of times in an array?

PostPosted: Mon Aug 06, 2012 4:18 am
by dexik
I have this array.

01 JOCKEY-NAME-ARRAY.
  02 JOCKEY-NAME OCCURS 100 TIMES PIC X(20).


It contains names of jockeys who participated in races. Some names occur several times. How do I find out which name(s) occur(s) the most number of times? I have an idea but it is too clumsy. Go through the array and move all individual names to individual arrays, then calculate and then compare the number of occurrences. I don't think I can use control break processing because the array is not sorted sequentially. Anyone has any ideas?

Re: How to calculate biggest number of times in an array?

PostPosted: Mon Aug 06, 2012 6:06 am
by Robert Sample
1. Sort the array to simplify the logic and use control breaks.

2. Create a second array and then scan through JOCKEY-NAME. If each name occurs in the second array, add 1 to a counter in that array. If the name doesn't occur in the second array, add it to the end and set the counter to 1.

Re: How to calculate biggest number of times in an array?

PostPosted: Mon Aug 06, 2012 11:49 am
by BillyBoyo
The "answer" always depends on the data. There are many possible "solutions", some of which will be a better fit for your data than others.

This is from a course/training, so also bear in mind specifically what you have been learning lately.

On what we know, I'd add a count to the table and instead of adding each race to the table, I'd add each jockey, setting count to one when including first time, and increasing the count for each time the jockey races. Once input is complete, go through the table to find the highest count. There are many "variations" possible with this, but that is the basic outline.