摘要:
摘自Handling Arbitrary StructuresOn the other hand, recursion—or equivalent explicit stack-based algorithms we’ll meetshortly—can be required to traverse arbitrarily shaped structures. As a simple exampleof recursion’s role in this context, consider the task of computing the sum of all thenumbers in a 阅读全文
摘要:
def moves_three(n, a=0, b=1, c=2): '''give a int -> return a list ''' if n==1: return ((a,c),) return moves_three(n-1,a,c,b)+\ ((a,c),)+\ moves_three(n-1,b,a,c)def moves(n, a=0, b=1, c=2): stack = [(True, n, a, b, c)] while stack: tag, n, a, b, c = st... 阅读全文