Selection Sort

This is a discussion on Selection Sort within the C++ Programming forums, part of the General Programming Boards category; *GBAHC A is smallest so we swap A and G A*BGHC B is smallest so swap B with B (don't ...

  1. #16
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    *GBAHC
    A is smallest so we swap A and G
    A*BGHC
    B is smallest so swap B with B (don't move)
    AB*GHC
    C is smallest so swap G with C
    ABC*HG
    G is smallest so swap G with H
    ABCG*H

    The alternative is your approach which would force you to move a lot of the array down one place on each step.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  2. #17
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Just so that you know though... This algorithm is trash. It is VERY slow. Bubble sort, Selection sort, and Insertion sort are the bottom of the barrel. Wait till you see quicksort and radix sort. Radix in particular just blows you away with speed but it's not as generic as quicksort.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Insertion and selection sort
    By Dashing Boy in forum C Programming
    Replies: 4
    Last Post: 08-29-2006, 05:42 PM
  2. Selection Sort problem #2
    By Twigstar in forum C++ Programming
    Replies: 7
    Last Post: 07-11-2005, 08:27 PM
  3. Selection Sort help
    By Twigstar in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2005, 09:39 PM
  4. Selection Sort
    By Bleueyes515 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2002, 09:33 PM
  5. selection sort records of chars
    By hew in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 04:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21