当可以把n问题化成类过程n-1问题时,可考虑递归调用自身
def hanoi(n, a, b, c):
if n>0:
hanoi(n-1, a, c, b)
print("moving from %s to %s" %(a,c))
hanoi(n-1, b, a, c)
当可以把n问题化成类过程n-1问题时,可考虑递归调用自身
def hanoi(n, a, b, c):
if n>0:
hanoi(n-1, a, c, b)
print("moving from %s to %s" %(a,c))
hanoi(n-1, b, a, c)