title: Trouble implementing a generic sort function
body: <p>I'm trying to implement a generic sort method for my homework and this is what I've got:</p>
  
  <pre><code>void mySort(int(*condition)(TElement,TElement), DynamicArray *arr)
  {
      if (arr == NULL)
          return;
      if (arr-&gt;elems == NULL)
          return;
      int i, j;
      for (i = 0; i &lt; arr-&gt;length - 1; i++)
          for (j = i; j &lt; arr-&gt;length; j++)
              if (condition(arr-&gt;elems[i], arr-&gt;elems[j]) == 0)
              {
                  TElement *aux = arr-&gt;elems[i];
                  arr-&gt;elems[i] = arr-&gt;elems[j];
                  arr-&gt;elems[j] = aux;
              }
  }
  </code></pre>
  
  <p>My condition struct is defined like this: </p>
  
  <pre><code>typedef int(*condition)(Country*, Country*);
  </code></pre>
  
  <p>// I have an array of "countries" and I need to sort them in all kinds of ways </p>
  
  <p>What I'm having trouble is where to write the actual condition methods (Maybe in my Repository module) and how to define it. 
  I tried like this:</p>
  
  <pre><code>int conditionAsByPop(Country* c1, Country* c2) \\Condition to sort ascending by population
  {
      if (c1-&gt;population &gt; c2-&gt;population)
          return 1;
      return 0;
  }
  </code></pre>
  
  <p>But I don't know how to actually call it ...</p>
  
  <pre><code>void sortAsByPop(CountryRepo* v)
  {
      mySort(conditionAsByPop(????), v);
  }
  </code></pre>
  
  <p>Thank you!</p>