From: Jamie Lokier <lk@tantalophile.demon.co.uk>
To: Oliver Xymoron <oxymoron@waste.org>
Cc: William Lee Irwin III <wli@holomorphy.com>,
Keith Owens <kaos@ocs.com.au>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC] 2.5.8 sort kernel tables
Date: Fri, 19 Apr 2002 14:46:13 +0100 [thread overview]
Message-ID: <20020419144613.C13926@kushida.apsleyroad.org> (raw)
In-Reply-To: <20020418135931.GU21206@holomorphy.com> <Pine.LNX.4.44.0204181507150.8537-100000@waste.org>
Oliver Xymoron wrote:
> Though we should probably just stick a simple qsort in the library
> somewhere.
Since we're comparing sort algorithms, I am quite fond of Heapsort.
Simple, no recursion or stack, and worst case O(n log n). It's not
especially fast, but the worst case behaviour is nice:
/* This function is a classic in-place heapsort. It sorts the array
`nums' of integers, which has `count' elements. */
void my_heapsort (int count, int * nums)
{
int i;
for (i = 1; i < count; i++) {
int j = i, tmp = nums [j];
while (j > 0 && tmp > nums [(j-1)/2]) {
nums [j] = nums [(j-1)/2];
j = (j-1)/2;
}
nums [j] = tmp;
}
for (i = count - 1; i > 0; i--) {
int j = 0, k = 1, tmp = nums [i];
nums [i] = nums [0];
while (k < i && (tmp < nums [k]
|| (k+1 < i && tmp < nums [k+1]))) {
k += (k+1 < i && nums [k+1] > nums [k]);
nums [j] = nums [k];
j = k;
k = 2*j+1;
}
nums [j] = tmp;
}
}
cheers,
-- Jamie
next prev parent reply other threads:[~2002-04-19 13:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-18 9:46 Keith Owens
2002-04-18 10:21 ` Matthias Andree
2002-04-18 10:32 ` Keith Owens
2002-04-18 10:52 ` Alan Cox
2002-04-18 13:02 ` Paul Mackerras
2002-04-18 15:38 ` Keith Owens
2002-04-18 15:52 ` Russell King
2002-04-18 16:09 ` Keith Owens
2002-04-18 13:59 ` William Lee Irwin III
2002-04-18 18:16 ` Kai Henningsen
2002-04-18 18:24 ` William Lee Irwin III
2002-04-19 11:46 ` David Weinehall
2002-04-18 20:20 ` Oliver Xymoron
2002-04-19 4:59 ` Matt
2002-04-19 13:45 ` Jamie Lokier
2002-04-19 13:46 ` Jamie Lokier [this message]
2002-04-19 14:25 ` Oliver Xymoron
2002-04-19 15:16 ` Tobias Wollgam
[not found] <1589.1019123186@ocs3.intra.ocs.com.au.suse.lists.linux.kernel>
[not found] ` <15550.50131.489249.256007@nanango.paulus.ozlabs.org.suse.lists.linux.kernel>
2002-04-18 17:51 ` Andi Kleen
2002-04-18 23:17 ` Keith Owens
2002-04-19 11:38 Randal, Phil
2002-04-20 5:19 ` Keith Owens
2002-04-20 8:50 ` Alan Cox
2002-04-20 9:40 ` Keith Owens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020419144613.C13926@kushida.apsleyroad.org \
--to=lk@tantalophile.demon.co.uk \
--cc=kaos@ocs.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=oxymoron@waste.org \
--cc=wli@holomorphy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®