🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4918

Re: Restrictions on qsort compare function?

#4918
From: T.E.Dickey
Date: Wed, 20 Mar 1996 13:47
17 lines
1119 bytes
James Bonfield (jkb@mrc-lmb.cam.ac.uk) wrote:
: Are there any limitations on what the sort function passed over to qsort can
: do or return? I know it's meant to return < 0, 0 or > 0 for the various
: compare operations, but which you return is purely up to your own comparison
: system.
In general, qsort will malfunction (at the least, you can get incorrect
sorting!) if

	compare(a,b) > 0 && compare(b,a) >= 0
or
	compare(b,a) > 0 && compare(a,b) >= 0

because it's not able to put the elements into disjoint sets.

-- 
Thomas E. Dickey
dickey@clark.net
Technical Details
Message-ID: <4ip2a8$p8b@clarknet.clark.net>
Path: arc1-ca.pugleaf.net!news.clark.net!not-for-mail
References: <4iokop$h4p@lyra.csx.cam.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.clark.net!not-for-mail
From: dickey@clark.net (T.E.Dickey)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: 20 Mar 1996 13:47:52 GMT
Organization: Clark Internet Services, Inc., Ellicott City, MD USA
Distribution: world
Message-ID: <4ip2a8$p8b@clarknet.clark.net>
References: <4iokop$h4p@lyra.csx.cam.ac.uk>
NNTP-Posting-Host: explorer.clark.net
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]