Question: Exercise 8 ( Index sorting ) Create method public static int [ ] indexSorting ( int [ ] a ) . It should return a
Exercise Index sorting
Create method public static int indexSortingint a It should return a table of indices
describing a sort of a but the table a should not be changed. The following example describes
an application.
; int index
indexSortinga; a is unchanged, index is now
The result now tells us that the smallest value of a is in position the second smallest value is
in position and so on The largest value can then be retrieved by looking at the last element
in the index table, so max is therefore which is
The code
for int ; alength; System.out.printaindexi
should therefore print out the values of ai in ascending order.
There is no emphasis on efficiency, only that the code works. You can create
auxiliary tables if you wish and you must create at least one, the table to be returned
The table a can have equal values, and then the solution will not be unambiguous. If for
example, the smallest value occurs twice, it does not matter which of them index refers to
But index must then refer to the second of them. If a is an empty table, the returned table
must also be an empty table.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
