473,324 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

sort on vector type

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
3 5636
"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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: {AGUT2} {H}-IWIK | last post by:
Guys, I have these headers: #include <stdlib> #include <math> #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <string> #include <algorithm>
9
by: JasBascom | last post by:
say i had 97456 and 23456 is there already a sort function to check which one begins with the smaller number rearrange it. in this case the bottom number should clearly be rearranged to the...
6
by: John Black | last post by:
I have a sort statement for vectr like this, sort(vec.begin(), vec.end(), EleSmaller); in running I find that the sort procedure falls into an endless loop, by adding some debug statement I...
4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
4
by: Johan | last post by:
Hi, Why does my vector not sort. What I understand is you have to overload the < operator, but that does not work. see code below Thanks Johan
8
by: laniik | last post by:
Hi. I have a problem using STL's built in sort that seems impossible to get around. if i have: -------------------------------- struct object { int val; }
10
by: eiji | last post by:
Hi folks, I have a problem compiling this under VC6! Maybe someone has some minutes to look at this: template<class T> class Compare { public: Compare(){}; virtual ~Compare(){};
8
by: markww | last post by:
Hi, If I have a vector of structs like this: struct IMAGE { unsigned char *pPix; string strName; int nNumber; };
11
by: Magcialking | last post by:
I wanna sort a pointer vector with the algorithm "sort" in STL like this: " int compare(vector<string*>::iterator a,vector<string*>::iterator b){ return (**a)<(**b); } ...
22
by: sandy | last post by:
I am trying to make a simulated directory structure application for a course. I am using a Vector to store pointers to my Directory objects (as subdirectories of the current object). In my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.