Counting sort

I am doing a non comparison based sort based on counting sort.

I have done a simulation on paper but I am having trouble actually coding it.

I know i need to create a count array and then after counting use another array that sums it up cumulatively and then with that make a new array that uses the cumulative sum to sort it. Can anyone guide me in the right direction?

I have 7 different schools for the count array. do i need a separate counter for each of them?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int schoolToIndex(string school) {
    if (school == "UCB")  return 0;
    if (school == "UCD")  return 1;
    if (school == "UCI")  return 2;
    if (school == "UCLA") return 3;
    if (school == "UCM")  return 4;
    if (school == "UCSD") return 5;
    if (school == "UCSF") return 6;
    
    cerr << "Unknown school " << school << endl;
    return -1;
}

/*
 * Sorts students by school. An implementation of counting sort.
 * @param students array already sorted by ID
 * @param len Array length
 */
void sortByGroupById(Student students[], int len) {
int counter;
int count[];
int sum[]; 

  for(int i =0; i <len; i++) {
   
}

}
Topic archived. No new replies allowed.