Results 1 to 3 of 3

Thread: Jolly Sorting

  1. #1
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default 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?

  2. #2
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    I have to split this array into 2 and then i think merge them into one resembling that post above..
    Java 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

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by socboy6579 View Post
    I have to split this array into 2 and then i think merge them into one resembling that post above..
    Java 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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. sorting problem
    By vasug in forum Advanced Java
    Replies: 2
    Last Post: 02-25-2010, 04:55 AM
  2. FIFO sorting
    By fanle in forum New To Java
    Replies: 3
    Last Post: 07-24-2009, 06:35 AM
  3. Sorting 10 numbers
    By perito in forum New To Java
    Replies: 56
    Last Post: 03-05-2009, 01:52 AM
  4. sorting
    By jot321 in forum New To Java
    Replies: 18
    Last Post: 10-02-2008, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •