/**
* 广度优先遍历
* **/
public void BreadthFirstTreeWalk(BSTreeNode<T> root, Action<BSTreeNode<T>> func) {
if (root == null) {
return;
}
List<BSTreeNode<T>> processQueue = new List<BSTreeNode<T>>();
processQueue.Add(root);
BSTreeNode<T> current;
while (processQueue.Count != 0) {
current = processQueue[0];
processQueue.RemoveAt(0);
func(current);
if (current.left != null) {
processQueue.Add(current.left);
}
if (current.right != null) {
processQueue.Add(current.right);
}
}
return;
}
原文:http://www.cnblogs.com/xiejunzhao/p/62d014c2f33887907af88f97ebccbe6b.html