我想维护两个队列,队列A用于弹出,队列B用于备份,所以如果我从A弹出所有对象,我该如何从B恢复队列A?
while (still has input)
A.push(input)
B.push(input)
while A is not empty
A.pop()
然后如何从B中恢复A ???与此同时,我仍然希望将B作为备份。
我知道一些非常愚蠢的方法,比如再分配一个队列C然后弹出所有Bout。然后从队列C恢复B
答案 0 :(得分:3)
一种方法是使用copy
模块。
import copy
while (still has input)
A.push(input)
B.push(input)
while A is not empty
A.pop()
A = copy.deepcopy(B)