You are viewing a single comment's thread. Return to all comments →
public static void countSort(List<List<String>> arr) { // Write your code here List<List<String>> buckets = new ArrayList<>(); for(int i =0; i < 100; i++){ buckets.add(new ArrayList<>()); } int n= arr.size(); for(int i =0; i < n ; i++){ Integer key = Integer.parseInt(arr.get(i).get(0)); String str = arr.get(i).get(1); if(i < n /2){ str = "-"; } buckets.get(key).add(str); } StringBuilder sb = new StringBuilder(); for(List<String> bucket : buckets){ for(String s : bucket){ sb.append(s).append(" "); } } System.out.println(sb.toString()); }
Seems like cookies are disabled on this browser, please enable them to open this website
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →