层序遍历

private void LevelOrder(TreeNode node)
{
    Queue<TreeNode> queue = new Queue<TreeNode>();
    queue.Enqueue(node);
    TreeNode treeNode = null;
    while(queue.Count>0)
    {
        treeNode = queue.Dequeue();
        if(treeNode.LeftChild!=null)
            queue.Enqueue(treeNode.LeftChild);
        if(treeNode.RightChild!=null)
            queue.Enqueue(treeNode.RightChild);
        Console.WriteLine(treeNode.data);
    }     
}   

  

posted on 2017-04-12 18:37  冰狼舞  阅读(95)  评论(0编辑  收藏  举报