#!/usr/bin/python # define three list var.
z1 = [1,2,3,4,5,6,7,"1st zhu"]
z2 = ["2st zhu"]
z3 = ["3st zhu"] counter = 0 def HANLTA(n, a, b, c):
global counter
if n==1:
counter = counter +1
c.insert(0,a[0])
del a[0]
return
else:
HANLTA(n-1, a, c, b)
counter = counter +1
c.insert(0,a[0])
del a[0]
HANLTA(n-1,b,a,c) HANLTA(7, z1, z2, z3) print z1
print z2
print z3
print counter
相关文章
- 09-30【Python学习之七】递归——汉诺塔问题的算法理解
- 09-30递归3之汉诺塔的实现
- 09-30Python实现常见算法[3]——汉罗塔递归
- 09-30Python基于递归算法实现的汉诺塔与Fibonacci数列示例
- 09-30python3实现几种常见的排序算法
- 09-30Python递归算法实现汉诺塔
- 09-30Python 实现汉诺塔问题(递归)
- 09-30Python Basic - 汉诺塔(Tower Of Hanoi)(递归实现)
- 09-30【数据结构与算法Python版学习笔记】递归(Recursion)——定义及应用:分形树、谢尔宾斯基三角、汉诺塔、迷宫
- 09-30Python算法_递归:汉诺塔