예제 #1
0
        /// <summary>
        /// Рисует узел дерева (<see cref = "RedBlackTree"/>)
        /// </summary>
        /// <param name="g"></param>
        /// <param name="node"></param>
        /// <param name="S"></param>
        private void DrawRBT_Node(Graphics g, RBT_Node node, Point S, int Dist)
        {
            //if (node.Parent != null) Dist -= 20;
            //int D = (GetParent(node) == null ? 100 : 50);
            Pen P  = new Pen(Color.Brown, 5);
            Pen P2 = new Pen(Color.Brown, 3);

            g.DrawEllipse(P, S.X, S.Y, 30, 30);
            P.Color = Color.Brown;
            if (node.Left != null)
            {
                Point S2 = new Point(S.X - (node.Parent == null ? (Dist -= 55) + 55 : (Dist -= 55)), S.Y + 90);
                g.DrawLine(P2, S.X + 15, S.Y + 15, S2.X + 15, S2.Y + 15);
                DrawRBT_Node(g, node.Left, S2, Dist);
            }
            if (node.Right != null)
            {
                Point S2 = new Point();
                if (node.Parent != null)
                {
                    S2 = new Point(S.X +
                                   (node.Left == null ? (Dist -= 55) : Dist), S.Y + 90);
                }
                else
                {
                    S2 = new Point(S.X + (node.Left == null ? (Dist -= 55) + 55 : Dist + 55), S.Y + 90);
                }
                g.DrawLine(P2, S.X + 15, S.Y + 15, S2.X + 15, S2.Y + 15);
                DrawRBT_Node(g, node.Right, S2, Dist);
            }
            SolidBrush B = new SolidBrush(node.Color == NodeColor.Red ? Color.Red : Color.Black);

            g.FillEllipse(B, S.X, S.Y, 30, 30);
            int d = 10 - (node.Value / 10 == 1 ? 3 : 0) - (node.Value < 0 ? 3 : 0);

            g.DrawString(node.Value.ToString(), label2.Font,
                         new SolidBrush(Color.FromArgb(255 - B.Color.R, 255 - B.Color.G,
                                                       255 - B.Color.B)) /*new SolidBrush(Color.White)*/, S.X + d, S.Y + 10);
            if (node.Chosen)
            {
                Pen P3 = new Pen(Color.Yellow, 5);
                g.DrawEllipse(P3, S.X - 5, S.Y - 5, 40, 40);
            }
        }
예제 #2
0
 private void RBT_Reset(RBT_Node N)
 {
     N.Left  = null;
     N.Right = null;
     N       = null;
 }