You are viewing a single comment's thread. Return to all comments →
public static void countSort(List<List<String>> arr) { Map<Integer,List<String>> map= new LinkedHashMap<>(); for(int i=0;i<arr.size()/2;i++){ arr.get(i).set(1, "-"); } List<String> s=new LinkedList<>(); int iValue; for(int i=0;i<arr.size();i++){ iValue=Integer.parseInt(arr.get(i).get(0)); if(map.containsKey(iValue)){ map.get(iValue).add(arr.get(i).get(1)); }else{ s.add(arr.get(i).get(1)); map.put(Integer.parseInt(arr.get(i).get(0)), new LinkedList<>(s)); s.clear(); } } List<Integer> sorted=map.keySet().stream().sorted().collect(Collectors.toList()); for(int i : sorted){ for(int j=0;j<map.get(i).size();j++){ System.out.print(map.get(i).get(j)+" "); } }
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 →
Java