Thread: Sorting an array of integers between two positions of the array

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    7

    Sorting an array of integers between two positions of the array

    Hi everyone.

    I am trying to create a code to sort an array of integer, but only between two positions of the array, not the all array.

    like this:

    array: 1 2 5 4 7 2 9 8
    index: 0 1 2 3 4 5 6 7

    i want to sort the array per exemple between the the index 2 and 5.
    the result is...
    array: 1 2 2 4 5 7 9 8

    Can anyone give me some help with this function?

    Thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Pass a pointer to the starting element and a size that indicates the number of elements.

    Jim

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Normally, your for loops have a stop when the sort iterator reaches the end of the array. In your case, just make the end of the array, as far as you want the sort to go - the length of the sort, if you will.

    It's the same logic and code, just limit the length in the for loops, and of course, change the starting point, as Jim has mentioned, above.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-26-2012, 10:50 AM
  2. Replies: 9
    Last Post: 04-07-2010, 10:03 PM
  3. counting array positions
    By Cpro in forum C++ Programming
    Replies: 4
    Last Post: 02-04-2008, 11:25 PM
  4. Sorting an array of integers
    By supermeew in forum C Programming
    Replies: 4
    Last Post: 05-02-2006, 04:58 AM
  5. Fill Positions of one Array into another Array
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 05-06-2002, 09:10 PM