Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This still won't fix the issue (you code doesn't work... never sorts) but it is updated to use List instead of Vector (Vector is obsolete, cannot be deprecated since official APIs depend on it). Unless you need the synchronization built into Vector use List/ArrayList instead.</p> <p>I also changed the array creation to be closer to generic (cannot truly do generic array creation). </p> <p>Finally I made the whole method generic so that it can work typesafely with things other than Object (so a List or List, etc...).</p> <p>It still gives warnings though. Perhaps you should work on getting the code to work properly before you worry about this particular warning (normally I would not suggest that, but with generics that can sometimes be a better way to do it).</p> <pre><code>public static &lt;T&gt; List&lt;T&gt; shellSort(List&lt;T&gt; ul) { int lcount = ul.size(); int colcount = 4; // 2^x List&lt;T&gt;[] currentCols = (List&lt;T&gt;[])Array.newInstance(List.class, 1); currentCols[0] = ul; for(; colcount &gt; 0; colcount = (colcount / 2)) { List&lt;T&gt;[] tmpCols = (List&lt;T&gt;[])Array.newInstance(List.class, colcount); for(int t1 = 0; t1 &lt; colcount; t1++) { tmpCols[t1] = new ArrayList&lt;T&gt;(); } int tcur = 0; int tcurlvl = 0; int ttmp = 0; for(int t2 = 0; t2 &lt; lcount; t2++) { List&lt;T&gt; vcur = currentCols[tcur]; List&lt;T&gt; vtmp = tmpCols[ttmp]; vtmp.add(vcur.get(tcurlvl)); // step to next place tcur++; ttmp++; if(tcur == currentCols.length) { tcur = 0; tcurlvl++; } if(ttmp == tmpCols.length) { ttmp = 0; } } } return ul; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload