# Jolly Sorting

• 12-17-2010, 01:59 AM
socboy6579
Jolly Sorting
I have to do some odd type of sorting i was wondering if i was on the right path.

consider the set of numbers {1, 5, 6, 8, 9, 2, 3, 4, 7}. An example of a jolly sort of this set would be {1, 5, 2, 4, 3, 9, 6, 8, 7}. The first two numbers of a jolly sort (if there are two or more numbers to be sorted) should be in ascending order

It is like a high low high low type of sort. I was wondering if i can make 2 arrays sort them in ascending and descending and then merge the both of them?

DO you think that would get the job done?
• 12-17-2010, 05:04 AM
socboy6579
I have to split this array into 2 and then i think merge them into one resembling that post above..
Code:

```import java.util.Arrays; public class Jolly {         public static void main(String[] args){                                 Integer[] ints = new Integer[20];                 ints[0] = 1;                 ints[1] = 17;                 ints[2] = 18;                 ints[3] = 3;                 ints[4] = 8;                 ints[5] = 6;                 ints[6] = 11;                 ints[7] = 20;                 ints[8] = 19;                 ints[9] = 2;                 ints[10] = 4;                 ints[11] = 5;                 ints[12] = 12;                 ints[13] = 16;                 ints[14] = 7;                 ints[15] = 10;                 ints[16] = 14;                 ints[17] = 13;                 ints[18] = 9;                 ints[19] = 15;                                                 Arrays.sort(ints);                                         } }```
how would i come across to split this array into 2 seperate ones
• 12-17-2010, 09:45 AM
JosAH
Quote:

Originally Posted by socboy6579
I have to split this array into 2 and then i think merge them into one resembling that post above..
Code:

```import java.util.Arrays; public class Jolly {         public static void main(String[] args){                                 Integer[] ints = new Integer[20];                 ints[0] = 1;                 ints[1] = 17;                 ints[2] = 18;                 ints[3] = 3;                 ints[4] = 8;                 ints[5] = 6;                 ints[6] = 11;                 ints[7] = 20;                 ints[8] = 19;                 ints[9] = 2;                 ints[10] = 4;                 ints[11] = 5;                 ints[12] = 12;                 ints[13] = 16;                 ints[14] = 7;                 ints[15] = 10;                 ints[16] = 14;                 ints[17] = 13;                 ints[18] = 9;                 ints[19] = 15;                                                 Arrays.sort(ints);                                         } }```
how would i come across to split this array into 2 seperate ones

This scenario always works fine if a[i] < a[i+1] for every value of i. First sort the array 'normally' and next merge the two halves together. This scenario fails if there are non-unique numbers in your array, e.g a= { 1, 1, 1, 1, 2, 3 }

kind regards,

Jos