class turn .cn code line log roo tree
- /*** 非递归 中序遍历* **/
- public void InOrderTreeWalk(BSTreeNode < T > root, Action < BSTreeNode < T >> func) {
- if (root == null) {
- return;
- }
- Stack < BSTreeNode < T >> stack = new Stack < BSTreeNode < T >> ((int)(2 * Math.Log(Count + 1)));
- BSTreeNode < T > current = root;
- while (current != null) {
- stack.Push(current);
- current = current.left;
- }
- while (stack.Count != 0) {
- current = stack.Pop();
- func(current);
- BSTreeNode < T > node = current.right;
- while (node != null) {
- stack.Push(node);
- node = node.left;
- }
- }
- }
null
二叉树 非递归遍历
来源: http://www.bubuko.com/infodetail-2020123.html