zoukankan      html  css  js  c++  java
  • Breadth-first

     

    Also, listed below is pseudocode for a simple queue based level order traversal, and will require space proportional to the maximum number of nodes at a given depth. This can be as much as the total number of nodes / 2. A more space-efficient approach for this type of traversal can be implemented using an iterative deepening depth-first search.

    levelorder(root)
      q = empty queue
      q.enqueue(root)
      while not q.empty do
        node := q.dequeue()
        visit(node)
        if node.left ≠ null then
          q.enqueue(node.left)
        if node.right ≠ null then
          q.enqueue(node.right)
    

      

  • 相关阅读:
    java
    java
    java
    java
    java
    java
    java
    java
    sed命令的用法
    linux系统产生随机数的6种方法
  • 原文地址:https://www.cnblogs.com/hephec/p/4603721.html
Copyright © 2011-2022 走看看