You are viewing a single comment's thread. Return to all comments →
public static List<Integer> countingSort(List<Integer> arr) { int[] frequency = new int[100]; List<Integer> sorted = new ArrayList<>(); // count frequency for(int i = 0; i < arr.size(); i++) { frequency[arr.get(i)]++; } for(int i = 0; i < frequency.length; i++) { int count = frequency[i]; if(count == 0) { continue; } for(int k = 0; k < count; k++) { sorted.add(i); } } return sorted; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 2
You are viewing a single comment's thread. Return to all comments →