The Full Counting Sort

  • + 0 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)+ " ");
            }
        });
    }