We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static List countingSort(List arr) {
// Write your code here
List count = new ArrayList<>();
for(int i = 0; i < 100; i++) {
count.add(0); //Here we are setting the value of entire count array to 0.
}
for(int i = 0; i < arr.size(); i++) {
int val = arr.get(i); //taking out the value from arr index i.
int currentcount = count.get(val); //then taking out the value from count at index val which gives us current count for that element val
count.set(val, currentcount + 1); //incrementing the count array at index val by 1
}
return count;
}
Counting Sort 1
You are viewing a single comment's thread. Return to all comments →
A simple solution using java
public static List countingSort(List arr) { // Write your code here List count = new ArrayList<>();
}