title: Sorting a list into multiple vertical columns
body: <p>Does anyone have a good algorithm for re-sorting an array of values (already pre-sorted) so that they can be displayed in multiple (N) columns and be read vertically? This would be implemented in .Net but I'd prefer something portable and not some magic function.</p>
  
  <p>A good example of it working is the ASP.Net CheckBoxList control rendering as a table with the direction set to vertical. </p>
  
  <p>Here's an example of the input and output:</p>
  
  <p>Input: </p>
  
  <p>Columns = 4<br>
  Array = {"A", "B", "C", "D", "E", "F", "G"}</p>
  
  <p>Output:</p>
  
  <p>ACEG<br>
  BDF</p>
  
  <p>Thanks!</p>
  
  <p><b>Updated (More Info):</b></p>
  
  <p>I think I might have to give a little more information on what I'm trying to do... Mostly this problem came about from going from using a CheckBoxList's automatic binding (where you can specify the columns and direction to output and it would output a table of items in the correct order) to using jQuery/AJAX to create the checkbox grid. So I'm trying to duplicate that layout using css with div blocks with specified widths (inside a container div of a known width) so they wrap after N items (or columns.) This could also be rendered in a table (like how ASP.Net does it.) </p>
  
  <p>Everything works great except the order is horizontal and when you get a large number of items in the list it's easier to read vertical columns.</p>
  
  <p>If the array doesn't have enough items in it to make an even grid then it should output an empty spot in the correct row/column of the grid.</p>
  
  <p>And if an array doesn't have enough items to make even a single row then just output the items in their original order in one row.</p>
  
  <p>Some other input/ouput might be:</p>
  
  <p>Columns = 3<br>
  Array = {"A", "B", "C", "D"}</p>
  
  <p>ACD<br>
  B</p>
  
  <p>Columns = 5<br>
  Array = {"A", "B", "C", "D", "E", "F", "G", "H"}</p>
  
  <p>ACEGH<br>
  BDF</p>
  
  <p>Columns = 5<br>
  Array = {"A", "B", "C", "D"}</p>
  
  <p>ABCD</p>