xiejunzhao
  1. /**
  2. * 非递归 中序遍历
  3. * **/
  4. public void InOrderTreeWalk(BSTreeNode<T> root, Action<BSTreeNode<T>> func) {
  5. if (root == null) {
  6. return;
  7. }
  8. Stack<BSTreeNode<T>> stack = new Stack<BSTreeNode<T>>((int)(2 * Math.Log(Count + 1)));
  9. BSTreeNode<T> current = root;
  10. while (current != null) {
  11. stack.Push(current);
  12. current = current.left;
  13. }
  14. while (stack.Count != 0) {
  15. current = stack.Pop();
  16. func(current);
  17. BSTreeNode<T> node = current.right;
  18. while (node != null) {
  19. stack.Push(node);
  20. node = node.left;
  21. }
  22. }
  23. }





分类:

技术点:

相关文章:

猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2021-07-31
  • 2021-12-21
  • 2022-01-06
  • 2021-10-29
相关资源
相似解决方案