You are viewing a single comment's thread. Return to all comments →
public static void countSort(List> arr) { // Write your code here int cnt = arr.size(); int hc = cnt / 2;
List<List<String>> sc = new ArrayList<>(cnt); for (int i = 0; i < cnt; i++) { sc.add(new ArrayList<>()); } int i = 0; for (int j = 0; j < cnt; j++){ int key = Integer.parseInt(arr.get(j).get(0)); String vlu = arr.get(j).get(1); if(i<hc){ vlu = "-"; } sc.get(key).add(vlu); i++; }; sc.forEach((t) -> { if(!t.isEmpty()){ System.out.print(String.join(" ", t)+ " "); } }); }
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 →
public static void countSort(List> arr) { // Write your code here int cnt = arr.size(); int hc = cnt / 2;