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); } }
时间: 2024-10-26 09:46:00