Win a copy of Modern frontends with htmx this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sorting multidimensional arrays (int)

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Marshal
Posts: 79082
376
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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}.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic