473,473 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

linked list quicksort

Does anyone know how to make quicksort for single linked list without
using array?
I know that mergesort is maybe better but I need quicksort!!

thnx
Nov 11 '06 #1
6 8875
Baltazar007 wrote:
>
Does anyone know how to make quicksort for single linked list
without using array?

I know that mergesort is maybe better but I need quicksort!!
Why? Mergesort handles the list in place. Quicksort requires an
array, and you don't have one unless you create an auxiliary
array. Total waste.

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

Nov 11 '06 #2
"Baltazar007" <OB*******************@gmail.comwrote in message
news:ej**********@news2.carnet.hr...
: Does anyone know how to make quicksort for single linked list without
: using array?
:
: I know that mergesort is maybe better but I need quicksort!!

MergeSort is not maybe better, it is guaranteed to be (as good)
or better than QuickSort when sorting a linked list.

QuickSort requires random access to the elements that are to
be sorted, which make it very unsuitable for a linked list.

What makes you say that you "need" QuickSort ?
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Nov 11 '06 #3
Ivan Vecerina wrote:
"Baltazar007" <OB*******************@gmail.comwrote in message
news:ej**********@news2.carnet.hr...
: Does anyone know how to make quicksort for single linked list without
: using array?
:
: I know that mergesort is maybe better but I need quicksort!!

MergeSort is not maybe better, it is guaranteed to be (as good)
or better than QuickSort when sorting a linked list.

QuickSort requires random access to the elements that are to
be sorted, which make it very unsuitable for a linked list.
Quicksort does not "require" random access. Pluck the first
node from the list and call it the partitioning element, walk
sequentially through the list reassigning its nodes to two new
lists depending on how they compare to the partitioning node (if
desired, make a third list for nodes that compare equal), sort
the two lists recursively, and concatenate.

Unfortunately, it seems difficult to avoid degeneracy in a
way that's both effective and cheap. Choosing the first node as
the partioning element is cheap, but runs a substantial risk of
degeneracy: for example, if the list is already in order or in
reverse order, each partitioning pass accomplishes almost nothing.
You could choose a "random" node from a list of known length at the
cost of generating one random number and traversing (on the average)
half the list before each partitioning pass, or you could make the
choice while building the list at the cost of generating a random
number for each node added. Neither of these strategies seems cheap.
What makes you say that you "need" QuickSort ?
His teacher, I bet.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 11 '06 #4

"Baltazar007" <OB*******************@gmail.comwrote in message
news:ej**********@news2.carnet.hr...
Does anyone know how to make quicksort for single linked list without
using array?
I know that mergesort is maybe better but I need quicksort!!

thnx
Quicksort on double linked list is possible

Quicksort on single linked list ? I dont know, maybe it's possible.

Dirtysort would be a better name.

Unlucky pivot = crash and burn ;)

Bye,
Skybuck.

Nov 11 '06 #5
Ivan Vecerina wrote:
"Baltazar007" <OB*******************@gmail.comwrote in message
news:ej**********@news2.carnet.hr...
: Does anyone know how to make quicksort for single linked list without
: using array?
:
: I know that mergesort is maybe better but I need quicksort!!

MergeSort is not maybe better, it is guaranteed to be (as good)
or better than QuickSort when sorting a linked list.

QuickSort requires random access to the elements that are to
be sorted, which make it very unsuitable for a linked list.

What makes you say that you "need" QuickSort ?
Ivan

I need it for homework
Nov 11 '06 #6
Baltazar007 wrote:

<snip>
I need it for homework
In that case don't you think it would be a good idea to at least make
some kind of attempt?

I would also point out that the best solution in C often is not good C++
and the best solution in C++ often is not C, so cross-posting between
comp.lang.c and comp.lang.c++ is rarely a good idea. I'll also bet your
teacher specified which language to use and you won't get very good
marks if you use the wrong one.
--
Flash Gordon
Nov 11 '06 #7

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

Similar topics

9
by: Goh, Yong Kwang | last post by:
I'm currently doing a project that has a array that supposed to be determined only at runtime. Originally, the prototype I did as a proof of theory (or a quick hack) So one method is to create a...
3
by: darth | last post by:
Does anyone have heap sorting with queue(doublely linked list) in C? I have heap sort with array but with queue, it's somewhat hard.
4
by: Peter Schmitz | last post by:
Hi, in my application, I defined a linked list just as follows: typedef struct _MYLIST{ int myval; void *next; }MYLIST; MYLIST head;
6
by: Baltazar007 | last post by:
Does anyone know how to make quicksort for single linked list without using array? I know that mergesort is maybe better but I need quicksort!! thnx
1
by: lg2530 | last post by:
template<class T> struct NODE { T data; NODE<T> * next; }; template<typename T> NODE<T>* QuickSortList( NODE<T>* list ) {}
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
12
by: aparnakakkar2003 | last post by:
can any one tell me if I give the followiing string in input: ABC abc BBC then how I can get ABC abc BBC
3
by: t | last post by:
What is the most efficient way to sort a linked list? In other words, how is std::list's sort() member function usually implemented? I was thinking of two approaches: (1) make an array of...
1
by: uydf | last post by:
hey, can someone help me with this problem- if every time K pivots are chosen and every pivot gets a linked list attached to it, with the numbers that are between this pivot and the next, and we do...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.