Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions