action rem oid 广度优先遍历 ret bre public bst
- /*** 广度优先遍历* **/
- 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;
- }
null
二叉树 广度优先遍历
来源: http://www.bubuko.com/infodetail-2020121.html