python篇
1.递归调用的时候,要注意会一层一层返回出去
例如:
def add(sum,x,y):
if sum<10:
x +=2
y +=2
sum=x+y
add(sum,x,y)
else:
sum=x+y
return sum
print(add(0,0,0))
def add2(sum,x,y):
if sum<10:
x +=2
y +=2
sum=x+y
sum=add2(sum,x,y)
return sum
else:
sum=x+y
return sum
print(add2(0,0,0))
以及我在实现二叉排序树的时候犯的一个错误
self.fathernode= self.findcurfathernode(value)
def findcurfathernode(self,value):
if self.right != None and self.right.value == value:
# print("111",self.value)
return self
elif self.left != None and self.left.value == value:
# print("222",self.value)
return self
else:
if self.value > value:
self = self.left.findcurfathernode(value)
else:
self = self.right.findcurfathernode(value)
# print("113331",self.value)
return self
2.if...else... 语法用太多