小编not*_*wer的帖子

如何实现广度优先遍历?

这就是我所拥有的.我以为预购是一样的,先把它与深度混合起来!

import java.util.LinkedList;
import java.util.Queue;

public class Exercise25_1 {
  public static void main(String[] args) {

    BinaryTree tree = new BinaryTree(new Integer[] {10, 5, 15, 12, 4, 8 });

    System.out.print("\nInorder: ");
    tree.inorder();
    System.out.print("\nPreorder: ");
    tree.preorder();
    System.out.print("\nPostorder: ");
    tree.postorder();

    //call the breadth method to test it

    System.out.print("\nBreadthFirst:");
    tree.breadth();

  }
}

class BinaryTree {
  private TreeNode root;


  /** Create a default binary tree */
  public BinaryTree() {
  }

  /** Create a binary tree from an array of objects */
  public BinaryTree(Object[] objects) { …
Run Code Online (Sandbox Code Playgroud)

java breadth-first-search

34
推荐指数
4
解决办法
10万
查看次数

标签 统计

breadth-first-search ×1

java ×1