算法图示: 运行效果: 详细代码: Option Explicit '洗16张牌(0-15),方便用十六进制显示 Dim Card() As Long Private Sub 洗牌() Dim i&, l&, r&, t& l = CARDMAX To CARDMAX r = Rnd * l t = Card(l) Card(l) = Card(r) Card(r) = t l = l - Next i End Sub Private Sub Command1_Click(…
Python有自带的洗牌算法函数shuffle(). 自己也通过学习也琢磨了一下它的实现,然后给出一个时间复杂度O(n),空间复杂度O(4)的例子: import random def shuffle1(lst) : l = len(lst) if l <= 1 : return lst i = 0 while l > 1 : j = int(random.random() * l) t = lst[i] lst[i] = lst[i+j] lst[i+j] = t i = i + 1 l =…
In a deck of cards, every card has a unique integer. You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck. Now, you do the following steps repeatedly, until all cards are revealed: Take the…