Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9509

Re: selection-sort in C

Message-ID <4E4C961C.22E0@mindspring.com> (permalink)
Date 2011-08-18 00:33 -0400
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: selection-sort in C
References <4e4a4fc9$0$313$14726298@news.sunsite.dk> <4E4AFBAA.6AD2@mindspring.com> <4e4b7347$0$306$14726298@news.sunsite.dk>

Show all headers | View raw


arnuld wrote:
> 
> > On Tue, 16 Aug 2011 19:22:18 -0400, pete wrote:
> 
> >> arnuld wrote:
> >>   for(i = 0; i != len; ++i)
> 
> > That loop is too long.
> >
> > To sort an array of (N) elements,
> > you only have to sort the first (N - 1) elements.
> 
> I wonder how it happens but I will use this :)

If an array has two elements, 
and the first element has been sorted into place by swapping,
then that means that the whole array has been sorted; right?

Phil Carmody phrased it better than I did.

> This was good.
> i don't understand why these techniques don't come to my
> mind:
> 
>  (1) to sort N elements you need to sort only N-1 elements
>  (2) i and i != idx replaced by i+1 and s[i] > s[idx]
> 
> Is there some special kind of practice/study needed to think like that ?

Writing sorting functions in C,
has been one of my hobbies for more than a few years.

http://www.mindspring.com/~pfilandr/C/q_sort/

http://www.mindspring.com/~pfilandr/C/e_driver/

I've also read some of Volume 3, Sorting And Searching,
from The Art Of Computer Programming, by Knuth.

Knuth considers Selection Sort, 
as being a category of sorts
in which the array is sorted from one end, 
one element at a time.
Heapsort is one kind of selection sort.
The sort that we have been looking at here in this thread,
I would call "simple selection sort".

-- 
pete

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

selection-sort in C arnuld <sunrise@invalid.address> - 2011-08-16 11:08 +0000
  Re: selection-sort in C Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-08-16 14:24 +0300
    Re: selection-sort in C arnuld <sunrise@invalid.address> - 2011-08-16 11:36 +0000
      Re: selection-sort in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-16 13:22 +0100
        Re: selection-sort in C arnuld <sunrise@invalid.address> - 2011-08-16 13:44 +0000
          Re: selection-sort in C Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2011-08-16 07:36 -0700
        Re: selection-sort in C Thomas Boell <tboell@domain.invalid> - 2011-08-16 18:03 +0200
          Re: selection-sort in C karnath <karnathtorjian@gmail.com> - 2011-08-16 16:25 +0000
            Re: selection-sort in C Willem <willem@toad.stack.nl> - 2011-08-16 16:33 +0000
          Re: selection-sort in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-16 20:03 +0100
        Re: selection-sort in C Keith Thompson <kst-u@mib.org> - 2011-08-16 09:27 -0700
      Re: selection-sort in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-17 20:17 +0000
        Re: selection-sort in C pete <pfiland@mindspring.com> - 2011-08-18 00:41 -0400
          Re: selection-sort in C Ben Pfaff <blp@cs.stanford.edu> - 2011-08-17 21:52 -0700
            Re: selection-sort in C pete <pfiland@mindspring.com> - 2011-08-18 01:07 -0400
              Re: selection-sort in C blp@cs.stanford.edu (Ben Pfaff) - 2011-08-17 22:36 -0700
                Re: selection-sort in C pete <pfiland@mindspring.com> - 2011-08-18 07:00 -0400
    Re: selection-sort in C BGB <cr88192@hotmail.com> - 2011-08-16 14:41 -0700
      Re: selection-sort in C Ian Collins <ian-news@hotmail.com> - 2011-08-17 10:10 +1200
        Re: selection-sort in C BGB <cr88192@hotmail.com> - 2011-08-16 17:25 -0700
          Re: selection-sort in C pacman@kosh.dhis.org (Alan Curry) - 2011-08-17 01:53 +0000
  Re: selection-sort in C Gene <gene.ressler@gmail.com> - 2011-08-16 05:27 -0700
  Re: selection-sort in C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-08-16 07:24 -0700
  Re: selection-sort in C pete <pfiland@mindspring.com> - 2011-08-16 19:22 -0400
    Re: selection-sort in C arnuld <sunrise@invalid.address> - 2011-08-17 07:52 +0000
      Re: selection-sort in C Angel <angel+news@spamcop.net> - 2011-08-17 10:15 +0000
      Re: selection-sort in C Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-08-17 13:22 +0300
      Re: selection-sort in C pete <pfiland@mindspring.com> - 2011-08-18 00:33 -0400

csiph-web