Thread: Array Sorting ???

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    4

    Arrow Array Sorting ???

    Hi to everyone...! How could i sort an array with float by decrease sorting?
    thanks..!

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    if is easy be selection sort, thanks again.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    #include <algorithm> and use std::sort instead of implementing a quadratic time sort like selection sort.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    keep in mind that std::sort by default sorts in ascending order (smallest to biggest). To make it sort in descending order, you have to supply a comparison function.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    thanks but i need with selection sort to do it.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what you are actually asking is for one of us to write a selection sort for you? That's not how it works here - you write the code, we explain what's wrong, how it works etc when you ask SPECIFIC questions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    IIRC
    Code:
    procedure selection_sort (a, first, last) :
       while last > first :
          choose highest item in a from [first, last), called max
          swap a(max) with a(last)
          decrement last
       end while
    done
    Last edited by whiteflags; 04-04-2008 at 02:58 AM.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    4
    Thanks , Perfect Gentleman...!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-31-2009, 12:34 PM
  2. two dimensional array sorting in C/C++
    By George2 in forum C Programming
    Replies: 16
    Last Post: 11-19-2006, 03:17 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM