How can I modify this algorithm which reorders a
    ?

后端 未结 5 528
再見小時候
再見小時候 2021-01-19 07:10

Background:

I asked this question yesterday:

How to modify the orientation of a

    spanning multiple columns?

    asking how to

5条回答
  •  迷失自我
    2021-01-19 07:20

    I think it's simpler to represent the items as a 1-D list (a,b,c...) and think about how to 1) get that from the original array and 2) transform it into the output array.

    Step 1 is easy, because the 1-D list is the same order as the

  • elements in the HTML source.

    So, suppose we have n elements and we want to put them into R rows and C columns but filling columns first. The element that goes in position (r,c) (0 based) is just element #R*c + r. And, as stated before, the order in the source file is the row-first order, or (0,0), (0,1), (0,2), ...

    If the # of elements doesn't fill the RxC grid exactly, then you have to add checks that the computed element number doesn't exceed n (easiest way is to pad the list with empty elements beforehand).

    Depending on the design requirements, you can also adapt this to minimize the number of blank elements given a fixed number of rows or columns.

提交回复
热议问题