Sorting integers

This is a discussion on Sorting integers within the C++ Programming forums, part of the General Programming Boards category; I searched the board but didn't find anything but two threads and neither were to helpful. How would I take ...

  1. #1
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280

    Question Sorting integers

    I searched the board but didn't find anything but two threads and neither were to helpful.

    How would I take an array of integers (or anyother type of numerical data type) and sort the numbers from least to greatest and place them back into the array in least to greatest order?

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Code:
    #include <algorithm>
    
    bool order (int a, int b)
    {
         return (a < b);
    }
    
    int main (void)
    {
         const int len = 25;
         int array[len];
         // let's say we filled array with random values =)
    
         std::sort<int*>(array, array + len, order);
         
         return 0;
    }
    Change a < b to a > b in order to sort greatest to least.
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    you know something..why am i always doing things the hard way...is there a book or something that shows us all the built in std functions, etc? i am always writing my own classes, functions, etc to do sort, etc..etc..please give me link or a good book
    nextus, the samurai warrior

  4. #4
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    It's good practice that you're writing the algorithms, but there are easy ways out
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01:24 PM
  3. Sorting an array of integers
    By supermeew in forum C Programming
    Replies: 4
    Last Post: 05-02-2006, 04:58 AM
  4. Replies: 6
    Last Post: 08-04-2003, 10:57 AM
  5. Sorting Integers
    By Beginnerinc in forum C Programming
    Replies: 7
    Last Post: 02-05-2003, 03:28 PM

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