コード例 #1
0
        public void DrawTree(Graphics g, Pen pen, SolidBrush brush, KDTreeNode <E> node, int xPos, int yPos, int xPad, int depth)
        {
            double maxNumPerDepth = Math.Pow(2, depth);

            if (node == null)
            {
                return;
            }
            if (node.Left != null && node.Left.Value != null)
            {
                DrawTree(g, pen, brush, node.Left, (xPos - xPad), yPos + 100, xPad - 15, depth + 1);
                if (node.Value != null)
                {
                    g.DrawLine(pen, new Point(xPos + 5, yPos + 5), new Point((xPos - xPad) + 5, (yPos + 100) + 5));
                }
            }
            if (node.Value != null)
            {
                g.DrawString(node.ToString(), new Font(FontFamily.GenericSansSerif, 7), brush, xPos, yPos - 20);
                g.FillEllipse(brush, xPos, yPos, 10, 10);
            }
            if (node.Right != null && node.Right.Value != null)
            {
                DrawTree(g, pen, brush, node.Right, (xPos + xPad), yPos + 100, xPad - 15, depth + 1);
                g.DrawLine(pen, new Point(xPos + 5, yPos + 5), new Point((xPos + xPad) + 5, (yPos + 100) + 5));
            }
        }
コード例 #2
0
 public void PostOrderTraversal(KDTreeNode <E> node)
 {
     if (node == null)
     {
         return;
     }
     if (node.Left != null)
     {
         PostOrderTraversal(node.Left);
     }
     if (node.Right != null)
     {
         PostOrderTraversal(node.Right);
     }
     if (node.Value != null)
     {
         Console.Write("\n" + string.Format("Value : {0:00},  Parent : {1}, Left Child : {2}, Right Child : {3}",
                                            node.ToString(),
                                            node.Parent != null ? node.Parent.ToString() : "No Parent",
                                            node.Left != null ? node.Left.ToString() : "No Left Child",
                                            node.Right != null ? node.Right.ToString() : "No Right Child")
                       );
     }
 }