title: Sort an array based on a tuple of 4 indices in C
body: <p>I have an interesting problem, which I have been struggling with for the past 2 days without a concrete solution.
  I am attempting to write a program in C which takes the following input array:</p>
  
  <pre><code>               1,1,5,5,
                 1,1,5,9,
                 2,2,6,2,
                 1,2,5,5,
                 1,3,6,6,
                 1,4,5,1,
                 4,1,5,6,
                 5,2,7,1,
                 1,1,6,0,
                 2,2,5,0,
  </code></pre>
  
  <p>step1: group the above array based on the 3rd column like this (bucket sort on tuple of 4 elements (i.e. each row), based on values of 3rd column:</p>
  
  <pre><code>               2,2,5,5
                 1,1,5,9,
                 1,2,5,5,
                 1,4,5,1,
                 4,1,5,6,
                 2,2,5,0,
                 2,2,6,2,
                 1,3,6,6,
                 1,1,6,0,
                 5,2,7,1
  </code></pre>
  
  <p>Step 2: Finally sort the elements based on the 4th column within each bucket like this:</p>
  
  <p>Final Output Array:</p>
  
  <pre><code>              2,2,5,0,
                1,4,5,1,
                2,2,5,5,
                1,2,5,5,
                4,1,5,6,
                1,1,5,9,
                1,1,6,0,
                2,2,6,2,
                1,3,6,6,
                5,2,7,1
  </code></pre>
  
  <p>The elements in the 1st and 2nd column do not play any role in the above sorting process.</p>
  
  <p>I have tried various techniques, using quicksort or bucket sort followed by a subsequent quicksort. Nothing has worked out quite right.
  Could anyone suggest a method of doing this in C, using appropriate data structures.</p>