This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes sorting multidimensional arrays (int) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "sorting multidimensional arrays (int)" Watch "sorting multidimensional arrays (int)" New topic
Author

sorting multidimensional arrays (int)

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
hi there.
i am trying to create a simulator for RoundRobin Process Scheduling Method.

i have this piece of code..



and the output as


P1 on index 0 = 20
P1 on index 1 = 20
P1 on index 2 = 20
P1 on index 3 = 20
P1 on index 4 = 10
P2 on index 0 = 20
P2 on index 1 = 20
P2 on index 2 = 20
P2 on index 3 = 20
P2 on index 4 = 20
P2 on index 5 = 20
P2 on index 6 = 10
P3 on index 0 = 20
P3 on index 1 = 10
P4 on index 0 = 20
P4 on index 1 = 20
P4 on index 2 = 20
P4 on index 3 = 10
P5 on index 0 = 20
P5 on index 1 = 20
P5 on index 2 = 10

Total = 21


I've realized that the output that I need is the sorted index...
it would probably mean that i need to sort the [j] index here.

or i need to do something else.
any idea?

i need to come up with like this one


P1 on index 0 = 20
P2 on index 0 = 20
P3 on index 0 = 20
P4 on index 0 = 20
P5 on index 0 = 20
P1 on index 1 = 20
P2 on index 1 = 20
P3 ....


and so on...

please help...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38474
    
  23
[pedantic mode]There is no such thing as a multi-dimensional array in Java, only arrays of arrays; you will see the Java™ Language Specification says the component of an array may itself be an array.[/pedantic mode]

You are trying to do it the hard way. You need to learn how to sort an int[] using the < or > operators. Hint: start by making a swapPairInArray() method like this.Overload your method to take an Object[].
Look up sorting algorithms, for example in Niklaus Wirth's book, available free on the net. Implement one of those algorithms for int[] arrays, then for Comparable[] arrays. As an example, try a String[] because String implements Comparable.Then work out how to sort things when their members are already arrays. You will have to work out what criterion you are using to tell whether {1, 2, 3) is greater or less than {3, 2, 1}.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting multidimensional arrays (int)