Thread: Selection Sort

  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

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, 04:42 PM
  2. Selection Sort problem #2
    By Twigstar in forum C++ Programming
    Replies: 7
    Last Post: 07-11-2005, 07:27 PM
  3. Selection Sort help
    By Twigstar in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2005, 08:39 PM
  4. Selection Sort
    By Bleueyes515 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2002, 08:33 PM
  5. selection sort records of chars
    By hew in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2002, 03:49 PM