递归算法解决汉诺塔问题
count = 0
def hanoe(n, source, tmp, target):
global count
if n == 1:
count += 1
print('{:8d} :{}---->{}'.format(count, source, target))
else:
hanoe(n-1, source, target, tmp)
count += 1
print('{:8d} .
原创
2020-11-04 23:43:37 ·
165 阅读 ·
0 评论