473,662 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on qsort library function

What is meant by stable qsort ?

Mar 3 '07 #1
14 2576
In article <11************ **********@n33g 2000cwc.googleg roups.com>,
su************* *@yahoo.com, India <su************ **@yahoo.comwro te:
>What is meant by stable qsort ?
A stable sort algorithm is one which leaves unchanged the order of
items that compare equal. C's qsort() is not guaranteed to do this.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 3 '07 #2
"su************ **@yahoo.com, India" wrote:
>
What is meant by stable qsort ?
If qsort is implemented via quicksort, it is not stable. Stable
means that equal keys appear in the output in the order in which
they appeared in the input. A stable O(nLOGn) sort is mergesort.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

Mar 3 '07 #3
CBFalconer <cb********@yah oo.comwrites:
"su************ **@yahoo.com, India" wrote:
>What is meant by stable qsort ?

If qsort is implemented via quicksort, it is not stable. Stable
means that equal keys appear in the output in the order in which
they appeared in the input. A stable O(nLOGn) sort is mergesort.
There are variants of Quicksort that are stable (at some cost in
speed).

Note that there is no implication in the standard that qsort() is an
implementation of the Quicksort algorithm; it could even be Bubblesort
or Bogosort in a sufficiently perverse implementation. You can
reasonably expect qsort() to use an O(n log n) algorithm. (If you're
curious, you can even investigate its internal behavior by adding
tracing code to your compar() routine.)

(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 3 '07 #4
Keith Thompson wrote:
>
.... snip ...
>
(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)
I suspect the famous 6 char external linkage name limit.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Mar 4 '07 #5
CBFalconer <cb********@yah oo.comwrites:
Keith Thompson wrote:
>>
... snip ...
>>
(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)

I suspect the famous 6 char external linkage name limit.
Sure, but parameter names don't have external linkage.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 4 '07 #6
On Mar 4, 8:57 am, Keith Thompson <k...@mib.orgwr ote:
(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)
Perhaps you could creat a better example?

Mar 4 '07 #7
Keith Thompson <ks***@mib.orgw rote:
CBFalconer <cb********@yah oo.comwrites:
Keith Thompson wrote:
>
(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)
I suspect the famous 6 char external linkage name limit.

Sure, but parameter names don't have external linkage.
True, but humans are habitual creatures. The habit was to make all
function names in the Standard 6 chars or less; that this wasn't
necessary in the case of a function pointer function parameter did not
manage to break the habit.

Richard
Mar 5 '07 #8

Richard Bos wrote:
Keith Thompson <ks***@mib.orgw rote:
CBFalconer <cb********@yah oo.comwrites:
Keith Thompson wrote:
>>
>(Hmm, I wonder why it's called compar() rather than compare().
>Historical reasons, I suppose.)
>
I suspect the famous 6 char external linkage name limit.
Sure, but parameter names don't have external linkage.

True, but humans are habitual creatures. The habit was to make all
function names in the Standard 6 chars or less; [ ... ]
Since the Standard library is a part of the implementation, it need
not be constrained by the rules of the C standard, isn't it?

Mar 5 '07 #9
In article <45************ *****@news.xs4a ll.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
>(Hmm, I wonder why it's called compar() rather than compare().
Historical reasons, I suppose.)
I suspect the famous 6 char external linkage name limit.
>Sure, but parameter names don't have external linkage.
>True, but humans are habitual creatures. The habit was to make all
function names in the Standard 6 chars or less; that this wasn't
necessary in the case of a function pointer function parameter did not
manage to break the habit.
Does the use of the name "compar" in the standard have any normative
effect at all? Surely implementations are not required to declare it
with that name (since no program can tell the difference)? It seems
to be a purely editorial choice.

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 5 '07 #10

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

Similar topics

8
2057
by: Joe | last post by:
Hi, The declaration of qsort is: void qsort(void *base, size_t count, size_t size, int (*comp)(const void *e1, const void *e2)); Since const is used in the declaration of the comparison function, why isn't the first argument to the qsort function declared as "const void *base" ? Many thanks,
5
3860
by: Steve | last post by:
can someone tell me how qsort function in <stdlib.h> is used (qsort(..........))? the function has a buffer, two void * parameters and the a pointer to a compare function. Thanks.
13
2603
by: buda | last post by:
I had some spare time and decided to try to implement the standard library qsort. This is a pretty simpleminded attempt, but it seems to be working. I have to point out that efficiency is not at all an issue for me, and this is purely a toy, so to speak. I'm quite aware that this is not the quickest way to implement the quicksort algorithm, but I basically just wanted to try to make a "generic function". I tested it with a few arrays of...
14
1337
by: streamkid | last post by:
i'm a learning newbie at c++... and i have the following question... reading some source code, i saw this: int function(const void * one, const void * two) { int var1, var2; var1 = *((int*)one); var2 = *((int*)two); /* sm other code here*/ }
30
2728
by: gaoxtwarrior | last post by:
a sort which is stable means it keeps the object's original order. A sort which is in place is stable. does anyone can explain me what is sort in place? thx.
4
1942
by: Szabolcs Nagy | last post by:
in the code below i thought the function call in g() could be easily optimized out so that g() becomes the same as h() (which becomes {return 0;}) executing 'gcc -O3 -S' i found that gcc does not do this now i'm wondering: is there something in the standard (eg c99) that prevents this optimization (theoretically)
18
2630
by: mdh | last post by:
May I ask the following. By K&R's own admission, the example used to describe function pointers is complex ( on P119). In addition, the use of casts has been stated by some on this group as being, again, a poor/bad example of it's use. For the moment, accepting these criticisms, I would still like to get some insight into why/how some things work as even poor code is enlightening, to me at least. The example uses K&R's version of...
17
235
by: Ron Ford | last post by:
Is qsort an intrinsic for C? -- We must respect the other fellow's religion, but only in the sense and to the extent that we respect his theory that his wife is beautiful and his children smart. 5 H. L. Mencken
61
5820
by: Ron Ford | last post by:
K&R has three different versions of qsort, and the ultimate one is supposed to be like the one in the std library. I'm trying to implement the first, which is in §4.10. I think I'm pretty close with this: void qsort(int v, int left, int right) { int i, last;
0
8432
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
8856
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
8633
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
7365
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
4179
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...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.