473,789 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4305

<du*********@gm ail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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*********@gma il.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
3859
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 operator< of the elements it consists of to sort the list. Now I´m interested to sort the elements by another < relation (I´m dealing with multivariate polynomials). Do I have to change the operator to sort the way it is most often needed and have to...
1
1904
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 error when I compile this code. Please tell me the difference. #include <iostream>
8
8066
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 environment. Is it sufficient to declare a bool variable 'Locked' which process set when they are using a particular object or do I need to consult some more low level platform-kernel documentation?? Regards
4
8053
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 differences?
2
3668
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
3758
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
2226
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 product - many fundamental issues were set long ago, and there's no reason to go back and revisit them just because the language has come out with a new set of tools. Case in point - the Standard Template Library. We fixed on a set of collection...
0
1217
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 the setstate and getstate methods to be able to do that. now the tricky part - my c++ class uses stl vectors (and possibly other stl containers). swig can handle that, except for the pickling. what should i do to be able to pickle the whole c++...
5
10440
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
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.