title: How do you perform a secondary sort while maintaining a primary sort
body: <p>For example I am writing a hash table with entries (string key, int count). First I am doing a selection sort to sort each entry by count. Then I want to sort them alphabetically while maintaining the sorted count. Is there a way to do this?</p>
  
  <p>Here is the primary sort.</p>
  
  <pre><code>void MyTrends::sortByCount(Entry* arr, int sizeOfArray) {
    int maxIndex; // the index of the element that has the highest count
    for(int i=0; i &lt; sizeOfArray-1; i++){
        maxIndex = i;
        for(int j=i+1; j &lt; m; j++){
            if(arr[j].getCount() &gt; arr[maxIndex].getCount()){ //if the count of element j is higher than the count of the Entry at the current max index then change the max index to j
                maxIndex = j;
            }
        }
        if (maxIndex != i) {
            Entry temp = arr[i]; //next 2 lines + this line are swapping max to first position and old first position to the position the max was in
            arr[i] = arr[maxIndex];
            arr[maxIndex] = temp;
        }
    }
  }
  </code></pre>
  
  <p>EDIT: After thinking some more, could this be accomplished by first sorting alphabetically and then using a stable sort to sort by count?</p>