The Full Counting Sort

  • + 0 comments

    What I meant is something like this. I am unsure if its better, considering the tradeoff is having to check some if statements just to avoid creating empty Buffers. I am unsure what the "price" for creating empty buffers is.. I am pretty sure this would be better for a large scale with lots of empty Buffers, but this is obviously not the case here.

    public static void main(String[] args) {

    Scanner scan=new Scanner(System.in);
    
    int size=Integer.parseInt(scan.nextLine());
    
    StringBuffer[] st=new StringBuffer[100]; 
    
    for(int i=0;i<size;i++)
    {
        String sts=scan.nextLine();
        String[] str=sts.split("[\\s]+");
        int k=Integer.parseInt(str[0]);
        String s;
        if(i<size/2)
            s="- ";
        else
            s=str[1]+" ";
        if(st[k] == null) st[k] = new StringBuffer();
        st[k].append(s);
    }
    
    for(int i=0;i<100;i++)
    {
        if(st[i] != null) System.out.print(st[i]);
    }
    

    }