title: How do I write a Drake sort algorithm for sorting an array in Java?
body: <p>I'm writing a Drake Sort Algorithm in java that will sort a collection of elements. The algorithm is supposed to work like this:</p>
  <p>An array for example: { -2, 4, 1, 4 }</p>
  <ol>
  <li>Get the max value of the array</li>
  <li>Get the min value of the array</li>
  <li>Create array with the size (max value - min value + 1)  = 7 (4-(-2)+1) = {0,0,0,0,0,0,0}</li>
  <li>Go through the array and for each element in the collection count the corresponding index in the array{ 1, 0, 0, 1, 0, 0, 2 }</li>
  <li>Create a new array that is the same size as the collection that I wanted to sort (4)</li>
  <li>Go trough the array and fill the new collection with the sorted values { -2, 1, 4, 4 }</li>
  </ol>
  <p>I'm not very good at writing algorithm and this is what I have so far (not completed I know)</p>
  <pre><code>    public int[] sort(int[] unsorted) {
  
      int maxValue = unsorted.length;
      int minValue = unsorted[0];
      int [] array = new int[maxValue - minValue + 1];
  
      for (int i = 0; i &lt; array.length; i++) {
          int newArray = array.length;
      }
  
  
  
      return array;
  </code></pre>
  <p>Do you know how I can improve this and actually get it to work?</p>