Question: I'm trying to do an insertion sort in which i sort the characters of a string, what do i replace inputString.charAt(j) with? note: //arr[j] =

I'm trying to do an insertion sort in which i sort the characters of a string, what do i replace inputString.charAt(j) with?
note: //arr[j] = arr[j-1] is an example that my professor used for an array. (just a reminder for myself)
Written in Java lang
public static String sort(String inputString) if (inputS tring null) t //insertion sortsort characters for(int i = 0; i inputstring.length(); i++) int index - inputString.charAt(i); int j- i; while( i> 0 && inputString.charAt (i-1) > index) //arr. [j] arr [ j-1] inputString.charAti.) (inputString.charAt (j-1)); inputString.charAti) inputString.charAt (index); return inputString // method returns the sorted version of the input string // the sorting must be accomplished using an insertion sort return null; //return null if string is empty
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
