Hi,
I have an array of n = 32 items with positive and negative values. First n/2 elements are positive and sorted by value and second n/2 elements are negative and sorted by value as well. I would like to sort the whole array by value, starting from the smallest negative value to biggest positive value which means if there are 32 elements the first 16 (n/2) sorted elements should contain the values of second 16 elements of the original array and the second 16 elements of the sorted array should contain the first 16 values of the original array.
Hypothetical example:
double[] original = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -16, -15, ..., -1};
double[] sorted = {-16, -15, ...., -1, 1, 2, ..., 16};
Does anyone know what is the best way to shift the elements to generate the sorted array from original?
This array is by the way tied to another array which doesn't have the elements sorted by size the same way and has to be shifted the same way as original so the array shouldn't be sorted by size, it has to be shifted.