Question
import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdOut; public class IndirectSort { // Is v // Exchange a[i] and a[j] (for indirect sort) private static void exch(int[] a, int
import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdOut;
public class IndirectSort { // Is v
// Exchange a[i] and a[j] (for indirect sort) private static void exch(int[] a, int i, int j) { int swap = a[i]; a[i] = a[j]; a[j] = swap; }
// Indirectly sort a[] using insertion sort, ie, not by rearranging a[], // but by returning an array perm[] such that perm[i] is the index of // the ith smallest entry in a[]. public static int[] indexSort(Comparable[] a) { ... }
// Test client. [DO NOT EDIT] public static void main(String[] args) { String[] a = StdIn.readAllStrings(); int[] perm = indexSort(a); int i; for (i = 0; i Problem 1. (Indirect Sort) Implement the static method sort in IndirectSort. java that indirectly sorts a using insertion sort, ie, not by rearranging a, but by returning an array pernl such that parnti] is the index of the ith smallest entry in Java IndirectSort NDIRECTINSERTIoNSORTEXANPLE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started