Algorithm to print out a shuffled list, in-place and with O(1) memory

后端 未结 10 1390
野趣味
野趣味 2020-12-09 11:51

After reading this question I started to wonder: is it possible to have a shuffling algorithm which does not modify or copy the original list?

To make it clear:

10条回答
  •  离开以前
    2020-12-09 12:48

    Those 10,000,000 items are only references (or pointers) to actual items, so your list will not be that large. Only ~40MB on 32-bit architecture for all references + size of internal variables of that list. In case when your items are smaller than reference size, you just copy whole list.

提交回复
热议问题