Answer to Question #74773 in C for jw

Question #74773
Improve the algorithm so can sort below array:

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]--;
}

}

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}
};
1
Expert's answer
2018-03-18T07:18:00-0400
Dear jw, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS