title: How to sort a 2d array in cpp by values of two columns?
body: <p>I have a <code>std::vector&lt; std::vector&lt;double&gt; &gt;</code> array, the entries of which are</p>
  <pre><code>1 80 -0.15 -0.9 -0.15 0.6 0 -1.5 
  1 81 -0.15 -0.9 -0.15 0.7 0 -1.6 
  1 82 -0.15 -0.9 -0.15 0.8 0 -1.7 
  1 83 -0.15 -0.9 -0.15 0.9 0 -1.8 
  .
  .
  .
  79 155 0.15 0.9 0.15 -0.9 0 1.8 
  79 156 0.15 0.9 0.15 -0.8 0 1.7 
  79 157 0.15 0.9 0.15 -0.7 0 1.6 
  79 158 0.15 0.9 0.15 -0.6 0 1.5 
  </code></pre>
  <p>Each row has 8 elements. I want to sort the array by the <strong>7th and 8th element</strong> using the <code>std::sort</code> function as</p>
  <pre><code>auto sortfunc = [](vector&lt;double&gt; va, vector&lt;double&gt; vb){ return (va[7] &lt; vb[7] ) &amp;&amp; (va[6]&lt; vb[6] ); };
  
  sort(array.begin(),array.end(), sortfunc );
  </code></pre>
  <p>The result is not a completely sorted array</p>
  <pre><code>3 153 -0.15 -0.7 0.1 -0.1 -0.25 -0.6 
  2 154 -0.15 -0.8 0.1 0 -0.25 -0.8 
  2 153 -0.15 -0.8 0.1 -0.1 -0.25 -0.7 
  2 152 -0.15 -0.8 0.1 -0.2 -0.25 -0.6 
  7 153 -0.1 -0.7 0.1 -0.1 -0.2 -0.6 
  7 154 -0.1 -0.7 0.1 0 -0.2 -0.7 
  .
  .
  .
  74 94 0.1 0.8 -0.05 -0.5 0.15 1.3 
  74 95 0.1 0.8 -0.05 -0.4 0.15 1.2 
  74 96 0.1 0.8 -0.05 -0.3 0.15 1.1 
  74 97 0.1 0.8 -0.05 -0.2 0.15 1 
  77 100 0.15 0.7 -0.05 0.1 0.2 0.6 
  77 99 0.15 0.7 -0.05 0 0.2 0.7 
  </code></pre>
  <p>This doesn't give me an array that is sorted by the given condition as the elements in 7th and 8th column doesn't appear in a particular order.</p>
  <p>What am I doing wrong here?</p>
  <p>Github Gist for the arrays is <a href="https://gist.github.com/ritajitk/a68058a9779e41ebadd896bfbd37d005" rel="nofollow noreferrer">here</a></p>