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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!