才疏学浅,智商不够,花了一晚上看了二叉树.记录一下: 1.二叉树的遍历 前序遍历:根节点->左子树->右子树 中序遍历:左子树->根节点->右子树 后序遍历:左子树->右子树->根节点 三层二叉树: A ↙ ↘ B C ↙ ↘ ↙ ↘ D E F G前序:先把BDE,CFG看做是A的左右子节点,因此是从A开始读,A作为第一个,然后进到左子节点 BDE, 这时再把它看
# coding = utf-8 a, b = 1, 2 print 'before change' print a, b a, b = b, a print 'after change' print a, b #>>> #before change #1 2 #after change #2 1 理解第7行a, b = b, a是关键. 再看看下面的代码,过渡到c = b, a: a = 1 b =2 c= b print c #2 c = b c指向了一个整数 c = b, prin
# encoding=utf-8class node(object): def __init__(self,data,left=None,right=None): self.data = data self.left = left self.right = right tree = node('D',node('B',node('A'),node('C')),node('E',right=node('G',node('F')))) # 先序def front(tree): if tree ==
class Node(object): def __init__(self, data=None, left=None, right=None): self.data = data self.left = left self.right = right class BTree(object): def __init__(self, root=None): self.root = root def is_empty(self): if self.root is None: return True