title: Implementing QuickSort in descending order on ArrayList
body: <p>I am trying to implement quickSort in Java on an arrayList, and I want the output to be in descending order. I have the following code:</p>
  
  <pre><code>    public static &lt;K, V extends Comparable&gt; ArrayList&lt;K&gt; quickSort(ArrayList&lt;K&gt; toSort, HashMap&lt;K, V&gt; results) {
  
          if (toSort.size() &lt;= 1) {
              return toSort;  //already sorted!
          }
  
          ArrayList&lt;K&gt; sorted = new ArrayList&lt;K&gt;();
          ArrayList&lt;K&gt; lesser = new ArrayList&lt;K&gt;();
          ArrayList&lt;K&gt; greater = new ArrayList&lt;K&gt;();
  
          K pivot = toSort.get(toSort.size()-1);   //use last element as pivot ??
  
          for (int i = 0; i &lt; toSort.size(); i++) {
  
              if (results.get(toSort.get(i)).compareTo(results.get(pivot)) &gt;=  0) {
                  greater.add(toSort.get(i));
              }
  
  
              else {
                  lesser.add(toSort.get(i));
              }
          }
  
  
          lesser = quickSort(lesser, results);
          greater = quickSort(greater, results);
  
  
          lesser.add(0, pivot);
          greater.addAll(lesser);
          sorted = greater;
  </code></pre>
  
  <p>However, instead of outputting something like: {99, 98, 97},</p>
  
  <p>I receive the following "doubled" output: {99, 99, 98, 98, 97, 97}</p>
  
  <p>I imagine the mistake is somewhere at the end in the concatenation of the lesser and greater lists, but I can't seem to figure out how to fix it. Any advice? Thanks</p>