摘要: 摘自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 阅读全文
posted @ 2014-02-23 15:25 LisPythoniC 阅读(444) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2014-02-23 13:59 LisPythoniC 阅读(228) 评论(0) 推荐(0) 编辑