I have to pass two arrays
1) that are filled with 1000 int’s between 0-100
2) that contains ten bins to sort the 1000 numbers.
How do I create the counter to sort numbers into ten bins such as 0-9, 10-19, 20-29, 30-39, 40-49,50-59 and so on to 90-99…
Would it be with an if/else that sorts them? If so, how do I add values into each bin? Would it be something like this?
This is what I have so far:
//initialize array of 1000 elements
int[] numbers = new int[1000];
int i = 0;
//initialize array of 10 bins
int[] bins = new int[10];
void setup() {
// Populate array with random number
for (int i = 0; i < numbers.length; i++) {
numbers[i] = ceil(random(0,99));
}
}
//function that sorts random numbers into bins
void counter(int[] numbers, int[] bins) {
}
If you want every number from
numbersin the rightbinthen I would use an array of 10 ArrayLists as the datastructure for yourbins.You then get a bin with (for example the first bin consisting of numbers with values 0-9):
If you want the count of numbers in a bin you can get it with (again an example with the bin 0-9)