how to change the code so that it can sort struct SResult sample[] = { {"A1234", 10}, {"A1239", 5}, {"A1394", 7}, {"A1434", 3}, {"A1454", 5}, {"A2884", 7}, {"A3235", 7}, {"A4334", 9}, {"A4884", 2}, {"A6934", 5}, {"A7265", 7}, {"A9559", 3} }; void counting_sort(struct SResult scoreArr[], int N, int final[]) { int freq[11] = {0}, cfreq[11] = {0}; int i, curScore; //1. Compute Frquency for (i = 0; i < N; i++){ freq[ scoreArr[i].score ] ++; } //2. Compute Cumulative Frequency cfreq[0] = freq[0]; for (i = 1; i < 11; i++){ cfreq[i] = cfreq[i-1] + freq[i]; } //3. Produce Final Position for (i = 0; i < N; i++){ curScore = scoreArr[i].score; final[ cfreq[ curScore ] – 1 ] = curScore; cfreq[curScore]–; } }

how to change the code so that it can sort

struct SResult sample[] = { {"A1234", 10}, {"A1239", 5}, {"A1394", 7}, {"A1434", 3}, {"A1454", 5}, {"A2884", 7}, {"A3235", 7}, {"A4334", 9}, {"A4884", 2}, {"A6934", 5}, {"A7265", 7}, {"A9559", 3} };

void counting_sort(struct SResult scoreArr[], int N, int final[]) {

int freq[11] = {0}, cfreq[11] = {0};
int i, curScore;

//1. Compute Frquency
for (i = 0; i < N; i++){
freq[ scoreArr[i].score ] ++;
}

//2. Compute Cumulative Frequency
cfreq[0] = freq[0];
for (i = 1; i < 11; i++){
cfreq[i] = cfreq[i-1] + freq[i];
}

//3. Produce Final Position
for (i = 0; i < N; i++){
curScore = scoreArr[i].score;
final[ cfreq[ curScore ] – 1 ] = curScore;
cfreq[curScore]–;
}
}

Don't hesitate - Save time and Excel

Are you overwhelmed by an intense schedule and facing difficulties completing this assignment? We at GrandHomework know how to assist students in the most effective and cheap way possible. To be sure of this, place an order and enjoy the best grades that you deserve!

Post Homework
Top