C++ array sorting

Hello.. I am stuck on how to get this started. Below is the prompt.

Next, you will create another array. This third array has 4 elements, each of which is an array of integers (an array or arrays). Each of the member arrays of ints is the same size as your data set (50) because it's possible (though very very unlikely) they could hold as many data as the data set size. Each of these 4 arrays represent categories of the data. The first of the member arrays is the indexes of the data set that are penguins with neurosis levels in the interval [1.00, 4.00); the second for neurosis levels in [4.00, 6.00); the third for the interval [6.00, 8.00), and the last for the interval [8.00, 10.00]. NOTE: [a, b) means include a, but upto and not b.....inclusive of lower end point and exclusive of upper end point. So, now you will fill those arrays appropriately with the indexes of the penguins taken from the data set.

My question is, is there a way to categorize an array based on these parameters? Thanks in advance
This is only a minor complication of previous assignments. It tricks you by being an “array of arrays”, but that isn’t really different than four separate arrays:

1
2
3
4
5
6
7
8
9
  int penguins1_to_lt_4 [MAX_PENGUINS];
  int penguins4_to_lt_6 [MAX_PENGUINS];
  int penguins6_to_lt_8 [MAX_PENGUINS];
  int penguins8_to_lt_10[MAX_PENGUINS];

  int num_penguins1_to_lt_4  = 0;
  int num_penguins4_to_lt_6  = 0;
  int num_penguins6_to_lt_8  = 0;
  int num_penguins8_to_lt_10 = 0;

Only now you have:

1
2
  int penguins[4][MAX_PENGUINS];
  int num_penguins[4] = { 0 };

Before, to add to an array, it was easy:

1
2
3
4
  if (penguin neurosis level < 4)
    penguins1_to_lt4[ num_penguins1_to_lt4++ ] = penguin_ID;
  else if (...)
    ...

Now you only need to catagorize the neurosis level:

1
2
  int NLI = ...;
  penguins[ NLI ][ num_penguins[ NLI ]++ ] = penguin_ID;

The outer dimension of both penguins[] and num_penguins[] is the neurosis level index (0..3).

Remember, the index is not the neurosis level. You can use an if..else to convert it:

1
2
3
4
if      (neurosis_level < 4) NLI = 0;
else if (neurosis_level < 6) NLI = 1;
else if (neurosis_level < 8) NLI = 2;
else NLI = 3;


Hope this helps.
Topic archived. No new replies allowed.