-You do a pass through the student array to count how many students there are in each school. You store the counts in a counts array.

-You allocate another array of Students with size equal to the input array. You will use this temp array to hold the sorted elements.

-Using the counts array you calculate the beginning index for each school in the sorted array by noticing that the starting index for a school is the cumulative number of students for all the schools before it in the array. E.g.: if the counts are 5, 10, 12 for schools a, b, c then the starting indexes for each school's students in the sorted array are 0, 5, 15

– You do another pass through the student array and whenever you encounter a student from a school you add that student to the right portion of the helper array and increment that portion's index.

-The helper array is now sorted by school and by ID within each school. Copy the helper array's elements to the input array.

*I'm having trouble with the last two bullet points. On paper i understand what the algorithm is doing but implementing the code is difficult for me.*

The code I have below uses a counter to keep track of how many students go into 7 different school represented by the index of the counter array. It then does a cumulative count. What i need to code now starts from the right of my temp array and uses the cumulative to sort the array.

```
void sortByGroupById2(Student students[], int len) {
int temp[len];
int count[7];
// Creates an array where schools are converted to ints by using schoolToIndex
for(int i = 0; i < len; i++) {
temp[i] =schoolToIndex(students[i].getSchool());
cout << i << " " << temp[i] << endl;
}
// Sets every index in count array to 0
for(int i =0; i < 7; i++) {
count[i]=0;
}
//Counts the number of student in 7 different schools
for(int j =0; j < len; j++) {
count[temp[j]]++;
}
cout << "====" << endl;
for(int i =0; i < 7; i++) {
cout<< i << " " <<count[i] <<endl;
}
cout << "====" << endl;
// cumulative counts so we get the starting index for each group
int total = 0;
for (int i=0; i<7; i++) {
int tmp = count[i];
count[i] = tmp +total;
total += tmp;
cout << i << " " << count[i] << endl;
}
// Sorts into a new array
for(int i=0; i <7;i++){
}
}
```