title: How to sort random elements of an array efficiently so that similar items appear together
body: <p>I'm starting to get myself into algorithms and I need help solving this kind of problem.</p>
  
  <p><strong>Task set:</strong></p>
  
  <blockquote>
    <p>An array contains sheep and goats in random order. Write a possibly
    fast method to rearrange the array, so that all goats are at the
    beginning and all sheep are at the end of the array. Consider the case
    when all animals are the same kind.</p>
  </blockquote>
  
  <pre><code>public class Sheep {
  
     enum Animal {sheep, goat};
  
     public static void main (String[] param) {
        // for debugging
     }
  
     public static void reorder (Animal[] animals) {
        // TODO!!! Your program here
     }
  }
  </code></pre>
  
  <p>Thank you for all your help!</p>