Thread: Sorting integers

  1. #1

    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


    #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
    you know something..why am i always doing things the hard 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
    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, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02: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, 04:28 PM