# Sorting an Array

In VC++ 6.0 if I have a large (approx 62k element) Carray and I wish to sort it, what is the most efficient way?  (Either a built in funcion of C++ I've missed or some sort of sorting algorith)

At the moent the program just goes through, gets teh smallest element, goes though, gets the next smallest etc... which was fine for only a few record but really slows things down where there are lots.

LVL 1
###### 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.

See what you can find on algorithms like Quicksort or Bubblesort.  Sorry I don't have the time at the moment to paste some example code here, but hopefully you can go from there.
0
Commented:
C has this generic purpose quicksort routine... it's qsort declared in stdlib.h
0

Experts Exchange Solution brought to you by

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

Commented:
>> what is the most efficient way?
Then a bubble sort would not be a good answer.  A quick sort would be good.

0
Commented:
Here's some code I got from a class on Codeguru and modified for my own use in a static function:

#define STRIDE_FACTOR         3

void SortStrArray(CStringArray* pArray)
{
BOOL bFound;
int iInner, iOuter, iStride = 1;
CString str1, str2;

while (iStride <= pArray->GetSize())
iStride = iStride * STRIDE_FACTOR + 1;

while (iStride > (STRIDE_FACTOR - 1))
{
iStride = iStride / STRIDE_FACTOR;

for (iOuter = iStride; iOuter < pArray->GetSize(); iOuter++)
{
bFound = FALSE;
iInner = iOuter - iStride;

while ((iInner >= 0) && !bFound)
{
str1 = pArray->GetAt(iInner);
str2 = pArray->GetAt(iInner+iStride);

if (str2 < str1)
{
pArray->SetAt(iInner+iStride, str1);
pArray->SetAt(iInner, str2);
iInner -= iStride;
}
else
bFound = TRUE;
}
}
}
}

I hope this helps you.

Steve
0
NIETOD,
Yes, I DO think that is a proper answer.  Considering he seemed to have no idea what to look for, and those algorithms can be found pretty easily.  It certainly was A LOT more help than what you provided him.  I'm new here, and I only tried to help.  Note: SteveGTR left a rather qualified "answer", and labeled it as a comment.  Go after him!  You need a life.
0
Author Commented:
I'm going to give lychee the points, since his is the solution I used.

SLim: Steve had to post his response as a comment, there can only be one proposed answer at a time.
0
Commented:
Slimfinger, if you are new to EE I recommend you spend a few days monitoring questions and refrain from answering.  I don't think anyone could argue that was not an appropriate answer for this site.  After reading some questions, I think you'll agree.

And the reason I didn't provide more information was that it wasn't needed, _lychee_, had done so.  Although I did point out that a bubble sort was a poor choice compared to the q-sort, which was not explicitly stated in _lychee_'s comments.
0
a) ONE click on the search button in Vis Studio and entering "Quicksort" leads you DIRECTLY to the qsort algorithm (the accepted solution).  Just *ONE* click.  Think about it. So, unless I'm blind, merely suggesting quicksort doesn't seem too far out of bounds.
Shame on me.

b) From what I can see, syzygy can just as easily award points to a contributed comment.

c) NIETOD - "refrain from answering"??? Just what is your point in here, anyway?  If the style doesn't quite fit, I will see that soon enough with no harm done.  In the meantime, I prefer to learn and to teach, not whatever you are doing.
0
Commented:
a) syzygy, didn't seem to think that "quicksort" helped.  Perhaps he doesn't have enough experience with VC to do the search?

>> b) From what I can see, syzygy can just as
>> easily award points
Note really.  When the question is locked that option is unavailble.

When you are locking a question, you are making a commitment to the client to help them to the best of your abilities.  If you know you can't help them sufficiently--due to inexperience, time constraints, or any other reason, you should not answer.  You can post a comment in that case.  That's why they are there.  And if the comment is actually sufficient to help the client, they can then award the points to you.  but if not, someone else can answer.

>> I will see that soon
>> enough with no harm done
You will see what?  If you don't see a problem in this question, what will it take?

>> not whatever you are doing
What is that?

0
Well, anyway, thank you for explaining a bit of the SOP...
0
Commented:
SOP?

It took me 6 months to figure out "AFAIK" , what's "SOP"?
0
"Standard operating procedure."  Never heard "AFAIK" myself.  (At least, not as far as I know.)
0
Commented:
lol... was that supposed to be corny?=P

AFAIK = as far as i know, which u used in the same post...
0