q_bic
asked on
Finding Largest Numbers in Array
Hi, How do write a function that returns the largest number in an array on the first execution of the loop, then on the second execution, it returns the second largest, then the third and so on till finally the smallest number.
Thanx!!
Thanx!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx for this great idea!!
int[] array = {3,4,8,1,4,2,9,10,2,5,45,4
Arrays.sort(array);
now, you array will be sorted, so you only have to loop over it once.
If you need to keep the order of the first array, allocate a second array and do System.arrayCopy before the sort.