From: Helge Hafting <helgehaf@idb.hist.no>
To: Manoj Sontakke <manojs@sasken.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: quicksort for linked list
Date: Fri, 09 Mar 2001 09:36:52 +0100 [thread overview]
Message-ID: <3AA89624.46DBADD7@idb.hist.no> (raw)
In-Reply-To: <3AA88891.294C17A0@sasken.com>
Manoj Sontakke wrote:
>
> Hi
> Sorry, these questions do not belog here but i could not find any
> better place.
>
> 1. Is quicksort on doubly linked list is implemented anywhere? I need it
> for sk_buff queues.
I cannot see how the quicksort algorithm could work on a doubly
linked list, as it relies on being able to look
up elements directly as in an array.
You can probably find algorithms for sorting a linked list, but
it won't be quicksort.
You can however quicksort the list _if_ you have room enough for an
additional data structure:
1. find out how many elements there are. (Count them if necessary)
2. Allocate a pointer array of this size.
3. fill the pointer array with pointers to list members.
4. quicksort the pointer array
5. Traverse the pointer array and set the links for each
list member to point to next/previous element pointed
to by the array. Now you have a sorted linked list!
Steps 1,2,3 & 5 are all O(n), better than the O(nlgn) for
quicksort.
Helge Hafting
next prev parent reply other threads:[~2001-03-09 8:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-09 7:38 quicksort for linked list Manoj Sontakke
2001-03-09 8:36 ` Helge Hafting [this message]
2001-03-09 11:09 ` James R Bruce
2001-03-09 11:50 ` Alan Cox
2001-03-09 18:39 ` Oliver Xymoron
2001-03-09 11:52 ` Rogier Wolff
2001-03-09 12:09 ` Thomas Pornin
2001-03-09 18:52 ` Oliver Xymoron
2001-03-10 16:15 ` Jerome Vouillon
2001-03-09 22:29 ` Michal Jaegermann
2001-03-10 18:50 ` Martin Mares
2001-03-10 23:54 ` Michal Jaegermann
2001-03-10 19:09 ` David Wragg
2001-03-12 19:20 ` Jamie Lokier
2001-03-13 6:59 ` James R Bruce
2001-03-09 18:23 ` Oliver Xymoron
2001-03-09 13:46 ` James Lewis Nance
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=3AA89624.46DBADD7@idb.hist.no \
--to=helgehaf@idb.hist.no \
--cc=linux-kernel@vger.kernel.org \
--cc=manojs@sasken.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.