util.py
def write_tree(tree, bitwriter):
	'''Write the specified Huffman tree to the given bit writer.  The
	tree is written in the format described above for the read_tree
	function.

	DO NOT flush the bit writer after writing the tree.

	Args:
	tree: A Huffman tree.
	bitwriter: An instance of bitio.BitWriter to write the tree to.
	'''
	# let node be the root node of tree first
	node = tree
	#if node is branch, write 1 and go left and right children
	if isinstance(node, huffman.TreeBranch):
		bitwriter.writebit(1)
		write_tree(node.left, bitwriter)
		write_tree(node.right, bitwriter)
	#if reach the leaf
	elif isinstance(node, huffman.TreeLeaf):
		#if EOF,write EOF (00)
		if node.value is None:
			bitwriter.writebit(0)
			bitwriter.writebit(0)
		else:
			#write character bits 01 followed by 8 bits of character
			bitwriter.writebit(0)
			bitwriter.writebit(1)
			bitwriter.writebits(node.value,8)
Write the specified Huffman tree to the given bit writer.  The
	tree is written in the format described above for the read_tree
	function.

	DO NOT flush the bit writer after writing the tree.

	Args:
	tree: A Huffman tree.
	bitwriter: An instance of bitio.BitWriter to write the tree to.
	
Write the specified Huffman tree to the given bit writer.  The
tree is written in the format described above for the read_tree
function.

DO NOT flush the bit writer after writing the tree.

A Huffman tree.
bitwriter: An instance of bitio.BitWriter to write the tree to.
Write the specified Huffman tree to the given bit writer . The tree is written in the format described above for the read_tree function . DO NOT flush the bit writer after writing the tree . A Huffman tree . bitwriter : An instance of bitio . BitWriter to write the tree to .
def write_tree(tree, bitwriter):
	node = tree
	if isinstance(node, huffman.TreeBranch):
		bitwriter.writebit(1)
		write_tree(node.left, bitwriter)
		write_tree(node.right, bitwriter)
	elif isinstance(node, huffman.TreeLeaf):
		if node.value is None:
			bitwriter.writebit(0)
			bitwriter.writebit(0)
		else:
			bitwriter.writebit(0)
			bitwriter.writebit(1)
			bitwriter.writebits(node.value,8)
def write_tree ( tree , bitwriter ) : node = tree if isinstance ( node , huffman . TreeBranch ) : bitwriter . writebit ( 1 ) write_tree ( node . left , bitwriter ) write_tree ( node . right , bitwriter ) elif isinstance ( node , huffman . TreeLeaf ) : if node . value is None : bitwriter . writebit ( 0 ) bitwriter . writebit ( 0 ) else : bitwriter . writebit ( 0 ) bitwriter . writebit ( 1 ) bitwriter . writebits ( node . value , 8 )
Write the specified Huffman tree to the given bit writer.
Write the specified Huffman tree to the given bit writer .
'''Write the specified Huffman tree to the given bit writer.  The
	tree is written in the format described above for the read_tree
	function.

	DO NOT flush the bit writer after writing the tree.

	Args:
	tree: A Huffman tree.
	bitwriter: An instance of bitio.BitWriter to write the tree to.
	''' # let node be the root node of tree first #if node is branch, write 1 and go left and right children #if reach the leaf #if EOF,write EOF (00) #write character bits 01 followed by 8 bits of character
tree
bitwriter