title: Sorting structure of arrays with qsort
body: <p>Normally sorting Array of structure objects is easy. Consider an Array of a structure (AOS)</p>
  
  <pre><code>#define ITEMS 10
  
  typedef struct MyStruct
  {
   char a;
   int  b;
  }tMyStruct;
  
  tMyStruct arr_mystruct[ITEMS];
  </code></pre>
  
  <p>I first fill this array of structure with values of &lt; a , b> pairs. </p>
  
  <p>If I now want to sort this array of structures according to the integer field, I can do it using libc qsort function by using a comparison function which takes two integer arguments.</p>
  
  <p>Now consider that I replace the above structure in AOS format with SOA format</p>
  
  <pre><code>#define ITEMS 10
  
  typedef struct MyStruct
  {
   char a[ITEMS];
   int  b[ITEMS];
  }tMyStruct;
  
  tMyStruct mystruct;
  </code></pre>
  
  <p>Now I can still use qsort to sort the array of integers b field, however this time I need to additionally sort a (array of characters)  w.r.t sorting order of b.</p>
  
  <p><strong>So my question is what is a possible efficient way to do sorting for data laid out in SOA format instead of usual AOS format?</strong> </p>
  
  <p>Can anyone help me with this ? Thanks!</p>