Exemple #1
0
 // смещение поддерева
 // ======
 public void Delta(HoTSNode p, int dx, int dy)
 {
     p.x -= dx; p.y -= dy;
     if (p.node_Left != null)
         Delta(p.node_Left, dx, dy);
     if (p.node_Right != null)
         Delta(p.node_Right, dx, dy);
 }
Exemple #2
0
 public void DeSelect(HoTSNode Node)
 {
     if (Node != null)
     {
         DeSelect(Node.node_Left);
         Node.visit = false;
         DeSelect(Node.node_Right);
     }
 }
Exemple #3
0
 // конструктор
 public HoTSNode(HoTSNode Left, HoTSNode Right, int Data, int x, int y)
 {
     node_Left = Left;
     node_Right = Right;
     node_Data = Data;
     this.x = x;
     this.y = y;
     this.visit = false;
     this.count = 1;
 }
Exemple #4
0
 // конструктор
 public HoTSTree(int VW, int VH)
 {
     tree_Top = null;
     tree_Canvas = new Bitmap(VW, VH);
     _Font = new Font("Courier New", 10, FontStyle.Bold);
 }
Exemple #5
0
        void HoTSGetNum(HoTSNode p, int Num, int Level)
        {
            if (p != null)
                if (Num == Level)
                {
                    Data += p.node_Data * p.count;
                    p.visit = true;
                }
                else
                {
                    Level++;
                        HoTSGetNum(p.node_Left, Num, Level);

                            HoTSGetNum(p.node_Right, Num, Level);
                }
            Level--;
        }
Exemple #6
0
        // рисование дерева
        void DrawNode(HoTSNode p)
        {
            int R = 17;
            if (p.node_Left != null)
                _Graph.DrawLine(_Ren, p.x, p.y, p.node_Left.x, p.node_Left.y);
            if (p.node_Right != null)
                _Graph.DrawLine(_Ren, p.x, p.y, p.node_Right.x, p.node_Right.y);

            if (p.visit)
                _Brush = (SolidBrush)Brushes.Yellow;
            else
                _Brush = (SolidBrush)Brushes.LightYellow;

            _Graph.FillEllipse(_Brush, p.x - R, p.y - R, 2 * R, 2 * R);
            _Graph.DrawEllipse(_Ren, p.x - R, p.y - R, 2 * R, 2 * R);
            string s = Convert.ToString(p.node_Data) + ":" + Convert.ToString(p.count);
            SizeF size = _Graph.MeasureString(s, _Font);
            _Graph.DrawString(s, _Font, Brushes.Black,
                p.x - size.Width / 2,
                p.y - size.Height / 2);

            if (p.node_Left != null)
                DrawNode(p.node_Left);
            if (p.node_Right != null)
                DrawNode(p.node_Right);
        }
Exemple #7
0
 // вставка
 public void Insert(ref HoTSNode t, int data, int x, int y)
 {
     if (t == null)
         t = new HoTSNode(null, null, data, x, y);
     else
         if (data < Convert.ToInt32(t.node_Data))
             Insert(ref t.node_Left, data, t.x - 50, t.y + 50);
         else
             if (data > Convert.ToInt32(t.node_Data))
                 Insert(ref t.node_Right, data, t.x + 50, t.y + 50);
             else
                 t.count++;
 }
Exemple #8
0
 // поиск по координатам
 public HoTSNode FindNode(HoTSNode p, int x, int y)
 {
     HoTSNode result = null;
     if (p == null)
         return result;
     if (((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)) < 100)
         result = p;
     else
     {
         result = FindNode(p.node_Left, x, y);
         if (result == null)
             result = FindNode(p.node_Right, x, y);
     }
     return result;
 }