In-place interleaving of the two halves of a string

后端 未结 6 1425
长发绾君心
长发绾君心 2021-02-20 07:30

Given a string of even size, say:

abcdef123456

How would I interleave the two halves, such that the same string would become

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 08:06

    The solution is here J. Ellis and M. Markov. In-situ, stable merging by way of perfect shuffle. The Computer Journal. 43(1):40-53, (2000).

    Also see the various discussions here:

    1. https://cs.stackexchange.com/questions/332/in-place-algorithm-for-interleaving-an-array/400#400
    2. https://cstheory.stackexchange.com/questions/13943/linear-time-in-place-riffle-shuffle-algorithm.

提交回复
热议问题