# Thread: Order the values of an int array only between two index numbers

1. ## Order the values of an int array only between two index numbers

Well, i am using the quicksort, the code is modified by me, and the code does:

i have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.

An example:
doubles array: (12,44;12,44;7,22; 12,44)
ints array: ( 4 , 2 , 3 , 1 )

now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 4 , 2 , 1 , 1 )

Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 1 , 2 , 4 , 1 )

How i can order the ints array only between an interval that is given by the interval of numbers that are equals in the doubles array?

Thanks

2. I suggest using an array of struct; but, you post is a little vague to me.
So, I might not be following what you want.

NOTE: I mean do NOT use parallel arrays use only one array.

Tim S.

3. yes it is true, but now i cant get back because it is almost done and i only need this function to complete the code.

i am using this function to order the arrays of doubles, and the arrays of ints follow the moves of the arrays of doubles.

Code:
```void quicksort(double *a, int n, int *array)
{
int i = 0;
int j = n-1;
double p = a[n/2];

assert(n>0);

do
{
while (a[i] > p)
i++;

while (p > a[j])
j--;

if (i<=j)
exchange(a, i++, j--,array);
}

while (i<=j);

if (j > 0)
quicksort(a, j+1,array);

if (i < n-1)
quicksort(a+i, n-i,array+i);
}```
i need to use this function again but now only between two numbers, not from the beginning of the array to the end.
Have you an idea how i can make it with this function?

4. What you want is called a multi-key sort, where anytime the first keys are equal, then the sorting decision rests with the order of the second key. qsort() does this rather easily by modifying the compare function.

It's a bit more complex to do it with this version of Quicksort, however. You can easily do this by adding a for loop after Quicksort is done sorting, however.

Code:
```int sorted=0;
while(!sorted) {
sorted=1;
for(i=starting index;i<ending index;i++) {
if(array[i].key1==array[i+1].k1 && array[i].key2 > array[i+1].key2) {
swap array[i] with array[i+1]
sorted=0;
}
}
}```

5. Essentially this is the same as sorting an array of structs, where your comparison breaks ties by looking at a second member of the struct.
The difference here is that you have a structure of arrays rather than an array of structures.