Python实现常见算法[3]——汉罗塔递归

#!/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
上一篇:用NSCalendar和UICollectionView自定义日历,并实现签到显示


下一篇:UML,类图