Efficient method to sort a CPtrarray?

What is the Efficient method to sort a CPtrarray in c++?
XPUSRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DanRollinsCommented:
Use qsort... as described here:
    Q216858
    How to use the quick-sort function to sort MFC CArray-derived classes on the MFC and Visual C++ run-time library
    http://support.microsoft.com/support/kb/articles/Q216/8/58.ASP

You will of course need to sort not on the *value* of the pointer itself, but on the value of the data to which each item points.  You write that logic into your Compare() function.

-- Dan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulCaswellCommented:
Hi XPUSR,

It depends on what you mean by efficient and a good deal on the type of data. For example, if most of the values are the same except just a few or most of them are already sorted then, believe it or not, bubblesort would be your best bet, with the normal tuning techniques.

Tell us a bit more about the data. Whats in it? How much does it vary? Can you add them one-at-a-time or do you get them in one big block? Etc ...

Paul
0
AndyAinscowFreelance programmer / ConsultantCommented:
What is efficient.
The bubble sort is very easy to code but takes a lot of time to sort compared to more advanced techniques.
However, if the array has, say, 8 pointers would the end user really notice it takes 0.001 seconds longer to execute?

(Bubble sort is just go through the array and swap adjacent items if they are not in order.  You keep doing that until no swaps are made.)
0
XPUSRAuthor Commented:
Thanks for the suggestions. How about conveting it to a vector and using the stl sort. How does this compare? The data in an array of stock performances.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.