Next: About this document ...
Up: Assignment 10: Arrays
One not-very-efficient way to sort the elements of an array
is to find the largest element and swap it with the first
element, then find the second-largest element and swap it with
the second, and so on.
- Write a method called indexOfMaxInRange that finds the
largest element in the given range, and returns its index.
You can modify your recursive version of maxInRange or
you can write an iterative version from scratch.
- Write a method called swapElement that takes an
array of integers and two indices, and that swaps the elements
at the given indices.
- Write a method called sortArray that takes an array of
integers and that uses indexOfMaxInRange and swapElement
to sort the array from largest to smallest.