Question: change all the for loops to while loop public int[] CountingSort (Container arr]) //The output array that will have sorted array// int output []- new

change all the for loops to while loop change all the for loops to while loop public int[] CountingSort (Containerarr]) //The output array that will have sorted array// int output []-

public int[] CountingSort (Container arr]) //The output array that will have sorted array// int output []- new int[arr.length]: int max-arrI0].getKey) for (int i-1: imax) ( max=arr [1] .getKey() ; int freql]-new int[max+1]: for (int r, iaax ;i++){ freqlil-0: for (int i-0: iarr[i+1].getkey)) Container tmp arr [i]; arr [i]-arr [i+1]: arr[i+1]-tmp; swapped - true; // if nothing moved, then array is sorted. II if (swapped-false) break // otherwise, reset the swapped flag so that it can be used in the next stage/ swapped-false; // move the end point back by one, because item at the end is in its spot/ end--; fro top to bottom, doing the same comparison as in the previous stage/ for (int )-start ; if (arr[i].getKey)>arr[i+1].getkey)) i-end-1; --)( Container tmp arr [i]; arr [i]-arr [i+1]: arr[i+1]-tmp; swapped true

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!