コード例 #1
0
ファイル: KdTree.cs プロジェクト: DharmanGersch/SpatialSlur
        /// <summary>
        ///
        /// </summary>
        public int GetMinDepth()
        {
            var q0    = new Queue <Node>();
            var q1    = new Queue <Node>();
            int depth = 0;

            q0.Enqueue(_root);

            while (true)
            {
                // iterate through nodes at the current depth and return if leaf is found
                while (q0.Count > 0)
                {
                    var node = q0.Dequeue();
                    if (node.IsLeaf)
                    {
                        return(depth);
                    }
                    q1.Enqueue(node.Left);
                    q1.Enqueue(node.Right);
                }

                // swap queues and continue on the next level
                CoreUtil.Swap(ref q0, ref q1);
                depth++;
            }
        }