This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "sorting multidimensional arrays (int)" Watch "sorting multidimensional arrays (int)" New topic

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

Joined: Oct 13, 2005
Posts: 38075
[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:
subject: sorting multidimensional arrays (int)
Similar Threads
Expand/Collapse Panels
Reading a text File from a TextArea
hashmap different keys with similar values and Arrays.sort()
please help. division on for loop and array.
some sort of pairing up on scheduling