美文网首页
BFS of a binary tree

BFS of a binary tree

作者: sherrysack | 来源:发表于2018-06-06 22:04 被阅读0次

    Here is the code for BFS for your Binary Tree.

    public void funcBFS(BTNode root){

    if (root == null)
    return;

    Queue<BTNode> q = new Queue<BTNode>();
    q.enqueue(root);

    while(!q.isEmpty()){
    BTNode n = q.dequeue();
    System.out.print(n.data+" ");
    if(n.left != null)
    q.enqueue(n.left);
    if(n.right != null)
    q.enqueue(n.right);
    }
    }

    相关文章

      网友评论

          本文标题:BFS of a binary tree

          本文链接:https://www.haomeiwen.com/subject/mswisftx.html