A question about sort stable | Bytes (2024)

gaoxtwarrior

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.

Mar 29 '07 #1

Subscribe Reply

30 A question about sort stable | Bytes (1) 2748 A question about sort stable | Bytes (2)

  • 1
  • 2
  • 3
  • >
  • Last »

santosh

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.

Mar 29 '07 #2

"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.

Mar 29 '07 #3

Eric Sosman

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

Mar 29 '07 #4

Richard Harter

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.

>

Mar 29 '07 #5

Keith Thompson

"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"

Mar 29 '07 #6

Richard Tobin

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.

Mar 29 '07 #7

lawrence.jones

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

Mar 29 '07 #8

CBFalconer

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

Mar 30 '07 #9

CBFalconer

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

Mar 30 '07 #10

  • 1
  • 2
  • 3
  • >
  • Last »

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

Similar topics

10 1974

UNIX-style sort in Python?

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...

Python

125 14852

What so special about PostgreSQL and other RDBMS?

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

Microsoft SQL Server

8 16604

STL sort compare function problem

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; }

C / C++

1 12847

Iterative Merge Sort Using Circular Linked List

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

C / C++

2 3821

Stable sort?

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

C# / C Sharp

13 4039

Seg faults in merge and quick sort

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;

C / C++

31 2556

what type of sort is this?

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;

C / C++

9 4517

Stable Sort Method - Where Can I Get One?

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.

C# / C Sharp

2 2567

Hi, I am getting the following errorTypeError: sort() takes nokeyword arguments

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

Python

9645

What is ONU?

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...

General

10147

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

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...

Online Marketing

9950

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

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...

General

1 7499

Access Europe - Using VBA to create a class based on a table - Wed 1 May

by: isladogs |last post by:

The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...

Microsoft Access / VBA

5381

Trying to create a lan-to-lan vpn between two differents networks

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...

Networking - Hardware / Configuration

5511

Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

1 4050

transfer the data from one system to another through ip address

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 we have to send another system

C# / C Sharp

2 3645

How to add payments to a PHP MySQL app.

by: muto222 |last post by:

How can i add a mobile payment intergratation into php mysql website.

PHP

3 2879

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

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...

General

A question about sort stable | Bytes (2024)

References

Top Articles
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6221

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.