Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
J. Moritz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on this problem all evening and any help would be appreciated.

I have a 5 element array (of type integer). I need to find the element of the array that holds the maximum value and keep the original corresponding index of that element. The Arrays.sort won't work on this one becuase the index changes for the element with the maximum value once the elements are sorted in ascending order.

Can anyone give me any example code? I just can't figure it out.. I've tried nested loops and etc..

Thanks
 
Mark Patrick
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without sorting the array, you'll have to loop through the array one time and test for the int value to be greater the previous greatest value:

 
J. Moritz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
finding the minimum and maximum values of an array while still retaining their original corresponding indices:

 
J. Moritz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic