title: How can I sort an array that dependes on the quantity of other?
body: <p>For Example I have this array:</p>
  
  <pre class="lang-c prettyprint-override"><code>G-&gt;colour = [2,1,0,1,0,1,0,1,2];
  G-&gt;vertex = [1,2,3,4,5,6,7,8,9];
  G-&gt;order = [1,2,3,4,5,6,7,8,9]; //the same of vertex
  </code></pre>
  
  <p>vertex 1 has colour 2, vertex 2 has colour 1, etc...<br>
  I need this solution <code>G-&gt;order = [1,9,3,5,7,2,4,6,8]</code>.  I want to sort order using the number of vertex with same colour in growing order, i.e.,     </p>
  
  <ul>
  <li>I have two vertex with colour 2 (vertexes: 1, 9)  </li>
  <li>I have three vertex with colour 0 (vertexes: 3,5,7)  </li>
  <li>I have four vertex with colour 1 (vertexes : 2,4,6,8)</li>
  </ul>
  
  <p>I have a function (RMBC) that sorts vertexes by colour. For example:</p>
  
  <pre class="lang-c prettyprint-override"><code>G-&gt;colour = [2,1,0,1,0,1,0,1,2];
  G-&gt;order = [1,2,3,4,5,6,7,8,9];
  </code></pre>
  
  <p>This returns the function <code>order = [3,5,7,2,4,6,8,1,9]</code>.  </p>
  
  <p>Besides I put the graph struct, and the greedy function that colours our vertexes. </p>
  
  <p>I have much more code but I think that with this is okey.</p>
  
  <p>Thanks!</p>
  
  <pre class="lang-c prettyprint-override"><code>typedef struct Graph
  {
      u32** vecinos;
      u32* vertexes;  // Position of vertexes
      u32* color; //Structure type declarations do not support initializers
      u32* grados;
      u32* order; //it has the order of vertex for greedy
      u32* visitados;
      u32 m; //number of edges
      u32 n; // number of vertex
      u32 max; // number of colors
      u32* indEnVecinos;
  } Graph;
  
  //RMBC
  u32* vert_color;
  char RMBC(Graph* G)
  {
      vert_color = G-&gt;color;
      qsort(G-&gt;order, G-&gt;n, sizeof(u32), compColoresNormal);
      return 0;
  }
  
  int compColoresNormal(const void *v1, const void *v2) {
      u32 color1 = vert_color[*(const u32 *)v1 - 1];
      u32 color2 = vert_color[*(const u32 *)v2 - 1];
      if (color1 &lt; color2)
      {
          return -1;
      }
      else if (color1 &gt; color2)
      {
          return 1;
      }
      else
      {
          return 0;
      }
  }
  // end RMBC
  
  //Greedy 
  u32 Greedy(Graph* G)
  {
      u32** aux = G-&gt;vecinos; 
      u32 max_color = 0;
      u32 nVer = G-&gt;n;
      u32* color_vecinos = (u32*)malloc(sizeof(u32) * nVer);
      memset(color_vecinos,0,nVer*sizeof(u32));
      u32 indice = binarySearch(G-&gt;vertexes,0,nVer-1,G-&gt;order[0]);
      G-&gt;color[indice] = 0;
      G-&gt;visitados[indice] = 1;
      u32 indice2 = 0;
      u32 reset = 0; 
      for (u32 i = 1; i &lt; nVer; ++i)
      {
          memset(color_vecinos,0,(reset+1)*sizeof(u32));
          indice = binarySearch(G-&gt;vertexes,0,nVer-1,G-&gt;order[i]);
          G-&gt;visitados[indice] = 1;
          u32 color = 0;
          reset = 0;
          for (u32 i = 0; i &lt; G-&gt;grados[indice]; ++i)
          {
              indice2 = binarySearch(G-&gt;vertexes,0,nVer-1,aux[G-&gt;indEnVecinos[indice]+i][1]);
              if(G-&gt;visitados[indice2])
              {
                  color_vecinos[G-&gt;color[indice2]] = 1;
                  if(reset &lt; G-&gt;color[indice2]) reset = G-&gt;color[indice2];
              }
          }
          for (u32 i = 0; i &lt; nVer; ++i)
          {
              if(!color_vecinos[i])
              {
                  color = i; 
                  break;
              }
          }
          G-&gt;color[indice] = color;
          if(color &gt; max_color) max_color = color;
          if(reset &lt; color) reset = color;
          if(reset == nVer) reset--;
      }
      free(color_vecinos);
      printf("terminé Greedy\n");
      return max_color + 1;
  }
  //end Greedy
  
  </code></pre>