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. 30 2727
gaoxtwarrior wrote:
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?
It means no significant additional storage is used while sorting.
"gaoxtwarri or" <ga***@cssweb.c om.cnwrote in message
>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?
Your premise is wrong. qsort() is an sort in place - if you print out the
array as it is sorting you will see values moving up and down within it -
but it is not stable. If Fred fred freddie and Freda all compare equal
because you are doing a case-insensitive comparision of the first four
letters, they will be contigous but in a random order when the sort
finished. A stable sort preserve the order of equal keys.
You can turn qsort into a stable sort by using the index as a tie breaker.
Malcolm McLean wrote On 03/29/07 15:28,:
"gaoxtwarri or" <ga***@cssweb.c om.cnwrote in message
>>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?
Your premise is wrong. qsort() is an sort in place - if you print out the
array as it is sorting you will see values moving up and down within it -
but it is not stable. If Fred fred freddie and Freda all compare equal
because you are doing a case-insensitive comparision of the first four
letters, they will be contigous but in a random order when the sort
finished. A stable sort preserve the order of equal keys.
You can turn qsort into a stable sort by using the index as a tie breaker.
Just to be clear: That's the "original" index, not the
index that the item happens to occupy at some random moment
during the sort.
-- Er*********@sun .com
On Thu, 29 Mar 2007 20:28:35 +0100, "Malcolm McLean"
<re*******@btin ternet.comwrote :
> "gaoxtwarrio r" <ga***@cssweb.c om.cnwrote in message
>>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?
Your premise is wrong. qsort() is an sort in place - if you print out the array as it is sorting you will see values moving up and down within it - but it is not stable. If Fred fred freddie and Freda all compare equal because you are doing a case-insensitive comparision of the first four letters, they will be contigous but in a random order when the sort finished. A stable sort preserve the order of equal keys. You can turn qsort into a stable sort by using the index as a tie breaker.
Your description applies to quicksort; IIANM qsort is a library routine
that can be implemented in any old way that the implementor feels like
using, including a stable sort.
>
"Malcolm McLean" <re*******@btin ternet.comwrite s:
"gaoxtwarri or" <ga***@cssweb.c om.cnwrote in message
>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?
Your premise is wrong. qsort() is an sort in place - if you print out
the array as it is sorting you will see values moving up and down
within it -
but it is not stable.
[...]
I think you're talking about the Quicksort algorithm. The C qsort()
function, declared in <stdlib.h>, may or may not use Quicksort; it's
allowed to use a either a stable or an unstable algorithm.
(I think there are also stable variants of Quicksort, but I don't know
the details.)
--
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"
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>>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?
>Your premise is wrong. qsort() is an sort in place - if you print out the array as it is sorting you will see values moving up and down within it - but it is not stable.
>I think you're talking about the Quicksort algorithm. The C qsort() function, declared in <stdlib.h>, may or may not use Quicksort; it's allowed to use a either a stable or an unstable algorithm.
The other part is true though: qsort() does sort in place, as far as
the input and output are concerned. And qsort() is not guaranteed to
be stable, and isn't in many implementations , so it serves as an
example of an in-place sort which is not necessarily stable.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
santosh <sa*********@gm ail.comwrote:
gaoxtwarrior wrote:
>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?
It means no significant additional storage is used while sorting.
Which means it has nothing to do with stability. An in-place sort need
not be stable. In fact, the standard library function qsort() is an
in-place sort, but it's not guaranteed to be stable and most
implementations are not.
-Larry Jones
It's not denial. I'm just very selective about the reality I accept.
-- Calvin
santosh wrote:
gaoxtwarrior wrote:
>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?
It means no significant additional storage is used while sorting.
Nonsense on the stable. It means items which sort equal appear in
the original order.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Keith Thompson wrote:
>
.... snip ...
>
(I think there are also stable variants of Quicksort, but I don't know
know the details.)
I don't think so, without using auxiliary data (such as indices).
I am prepared to be proven wrong on this.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kotlin Sam |
last post by:
For a while at least I have to work in Windows rather than UNIX, which
is more familiar. I'm trying to do with Python some of the things that
I've done for years in shell, in particular, sort. The shell sort is
pretty easy to use:
% sort -t, +2 +5 imputfilename <return>
where -t is the field separator, in this case a comma, , and +2 and
+4 are the fields to be sorted, in that order. Actually, the fields are
zero-based, so the first and...
|
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: laniik |
last post by:
Hi. I have a problem using STL's built in sort that seems impossible
to get around.
if i have:
--------------------------------
struct object
{
int val;
}
|
by: Booser |
last post by:
// Merge sort using circular linked list
// By Jason Hall <booser108@yahoo.com>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
//#define debug
|
by: cody |
last post by:
I need a sort method for stable sorting, that is, if two values have the
same value they won't be swapped. Will there be such a thing in whidbey?
--
cody
www.deutronium.de.vu || www.deutronium.tk
| |
by: ralphedge |
last post by:
These sorts work fine on 100000 ints but if I go much higher they will
both segmentation fault
**************************MERGESORT*********************
mergesort(int *a, int size) //a is pointer to the array, size is # of
elements
{
int b;
|
by: Lane Straatman |
last post by:
void s_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
size_t bytes;
unsigned char *array, *after, *i, *j, *k, *p1, *p2, *end, swap;
array = base;
after = nmemb * size + array;
if (nmemb (size_t)-1 / 4) {
nmemb /= 4;
|
by: Gary Brown |
last post by:
Hi,
I need a stable sort and can find none in the MS libraries.
Is there a simple one available on the internet? It needed
for sorting various lists of maybe 1K elements - mostly
ListView columns.
I took an algorithms course many years ago and learned
to really hate writing sort routines or I would just write one.
|
by: gaurav kashyap |
last post by:
Hi all,
I am using python version 2.3.in a program ,
I have called the sort function.Wherein,
a.sort(reverse=True)
is giving the following error:
TypeError: sort() takes no keyword arguments.
It works in python 2.4,What can be the alternative in python 2.3
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |