• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Counting Sort in C++

ecom

Senior member
I need to write a counting sort using c++ and I have put it here:
http://codepad.org/MpTugOur

Everything works, but counting sort is really slow. My program has been running for almost 12 hours and hasn't gone half way through.

Specifically, my counting sort starts with line 564. My main program file is here: http://codepad.org/qI5yLfxV

The instructor was us to run the program with 4 million in the command line argument. Specifically, the program seems to be taking longest doing counting sort using 4 million.

I am not to modify the main.cpp file. Only the sorting file is modified in the assignment. Did I write the counting sort correctly?
 
A couple of things I see.

1. You are using functions very frequently for values that don't change. Don't do that. For example. 576, count begin shouldn't change at all in that loop, so why go out and find out what it is every iteration?

2. I'm not sure that you are implementing the counting sort right. you should only have to go through the data once to do a counting sort right, you are doing it several more times. Check your algorithm, make sure you are doing it right.
 
Back
Top