By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

sort on vector type

P: n/a
Hi there,

I am reading through accelerated c++, and have just finshed chapter 3.
My question is what sorting algorithm is used on vectors? e.g. if I had:

std::vector<int> scores;
// adding some values to scores
std::sort(scores.begin(), scores.end());

then what algorithm is used? or is this implementation specific?

Thanks
Allan
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote...
I am reading through accelerated c++, and have just finshed chapter 3.
My question is what sorting algorithm is used on vectors? e.g. if I had:

std::vector<int> scores;
// adding some values to scores
std::sort(scores.begin(), scores.end());

then what algorithm is used? or is this implementation specific?


It is implementation-specific, it is only defined to adhere to
certain performance requirements. It's probably a quick-sort.

Victor
Jul 19 '05 #2

P: n/a

Allan Bruce <al*****@TAKEAWAYf2s.com> wrote in message
news:bg**********@news.freedom2surf.net...
Hi there,

I am reading through accelerated c++, and have just finshed chapter 3.
My question is what sorting algorithm is used on vectors? e.g. if I had:

std::vector<int> scores;
// adding some values to scores
std::sort(scores.begin(), scores.end());

then what algorithm is used?
The language standard does not specify the
algorithm, only the 'complexity'.
or is this implementation specific?


Yes.

Also note that this is not specific to 'vector'.
'std::sort' can be used with any container
which supports random access iterators (this
includes arrays).
-Mike

Jul 19 '05 #3

P: n/a
Allan Bruce wrote:
I have programmed my own sorts as macros in c, and just wondered if it was
worthwhile using them over the standard sorts.
Allan


Almost certainly not. The standard routines are much less likely to have
errors, are available everywhere (while your versions may have
non-portable parts), and are probably faster than yours. Besides that,
they are standard. Everyone recognizes them and knows what they mean.
Add to that the fact that macros are bad, and the standard routines fit
with the rest of the standard library framework, and there's really no
good reason to use your own routines, and a number of reasons not to.

-Kevin

--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.