473,378 Members | 1,346 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,378 software developers and data experts.

what is the difference between sort() (in stl) & qsort(stdlib.h)

hello,
can someone tell me
what is the difference between sort() (in stl) & qsort(stdlib.h)
thanks in advance.

Oct 22 '05 #1
2 4273

<du*********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
hello,
can someone tell me
what is the difference between sort() (in stl) & qsort(stdlib.h)


The essential differences:

std::sort uses iterators (which include pointers),
whereas qsort uses pointers.

std::sort has a default comparison operator (< operator),
whereas qsort requires a user-supplied comparison function.

std::sort can be used to sort standard containers (except
std::list, which has its own member sort function) or arrays,
qsort cannot sort standard containers, but only arrays.
-Mike
Oct 22 '05 #2

du*********@gmail.com wrote:
hello,
can someone tell me
what is the difference between sort() (in stl) & qsort(stdlib.h)
thanks in advance.


The most important different is that std::sort() is typesafe whereas
qsort() is not. In other words, when using qsort() a program is given a
pair of void * pointers to rank in its comparison routine; with
std::sort() the program is given two "pointers" (technically,
iterators) of a specific type and asked to rank them. Preserving the
type information in the comparison routine makes mix-ups less likely
when using std::sort(), and the comparison routines themselves are much
easier to match with the type that each knows how to rank.

Greg

Oct 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hagen | last post by:
Hello, got a short question about the sort algorithm of the list container in the Standard Template Library: Can I use the sort algorithm with another parameter to sort by? Sort uses the...
1
by: learning_C++ | last post by:
Hi, I compiled some code. In the function friend ostream& operator<<(ostream& os, const complex c); I use the later argument complex c and complex& c. I can get the same values and there is no...
8
by: Michael | last post by:
Don't shoot me down guys, I know the Standard says nothing of threads and all.... As i understand it the STL does not support multithreading, however I want to use the STL in a multithreaded...
4
by: orangepic333 | last post by:
Could someone tell me what's the difference between the two? Is it that a class is used within an OO language while a component can be exported between OO languages? Are there other...
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
9
by: Jeff Dege | last post by:
I've been programming in C++ for a good long while, but there are aspects of the language I've never needed, and hence never bothered to really learn. It's the curse of working on a developed...
0
by: Ondrej Marsalek | last post by:
hello, i have the following problem/question: i have a c++ class i would like to wrap using swig, easy so far. i want to be able to pickle it as well and i understand that i need to implement...
5
by: bhushanbagul | last post by:
Hi All Please let me know exactly what difference i and g makes in oracle version i.e. when we say oracle 10g or oracle 11i Thanks Bhushan
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.