title: C# Reordering array by index even ascending odd descending
body: <p>I need to reorder an array by skipping one element each time, first taking the evenly indexed elements ascending, and then taking the oddly indexed elements in descending order.</p>
  
  <p>For example, say I have an array of <code>double</code> that is ordered like this:</p>
  
  <p>[0, 0.3, 0.7, 1.1, 1.5, 1.9, 2.3, 2.7, 3.1, 3.5, 3.9]</p>
  
  <p>I would like to have it ordered like this:</p>
  
  <p>[0, 0.7, 1.5, 2.3, 3.1, 3.9, 3.5, 2.7, 1.9, 1.1, 0.3]</p>
  
  <p>As you can see, I'm not interested in ordering by the values, but only the index of the elements. I can't find an overload of Array.Sort or IEnumerable&lt;>.OrderBy that gives the index, so I can't seem to use that.</p>
  
  <p>I feel a bit ashamed to ask what seems like such a simple question, but I can't figure out how to do that elegantly. I can of course do it with a foreach loop and playing with the indexes, but I'm "translating" some Matlab code and this particular part is made with this elegant (albeit complex to understand if you're not used to that kind of things) one liner:</p>
  
  <pre><code>y = y([1:2:n 2 * floor(n / 2):-2:2],:); % n being the number of elements in the array y
  </code></pre>