Beispiel #1
0
 public static void DrawT(PaintEventArgs e, List <List <int> > list, MyTree myT)
 {
     if (list != null)
     {
         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
         Font my  = new Font("Arial", 10, FontStyle.Bold);
         Pen  pen = new Pen(Color.FromArgb(128, 0, 128), 3)
         {
             EndCap = LineCap.ArrowAnchor
         };
         List <List <int> > cn = new List <List <int> >();
         for (int i = 0; i < list.Count; i++)
         {
             for (int j = 1; j < list[i].Count; j++)
             {
                 cn.Add(new List <int> {
                     list[i][j - 1], list[i][j]
                 });
             }
         }
         int k  = 100; // zoom
         int k2 = 8;
         foreach (var item in cn)
         {
             NodeTree one = myT.Search(item[0], myT.Top);
             e.Graphics.DrawString(one.Data.ToString(), my, Brushes.Black, k * one.X - k2, k * one.Y);
             NodeTree two = myT.Search(item[1], myT.Top);
             e.Graphics.DrawString(two.Data.ToString(), my, Brushes.Black, k * two.X - k2, k * two.Y);
             e.Graphics.DrawLine(pen, k * one.X, k * one.Y + 20, k * two.X, k * two.Y);
         }
     }
 }
Beispiel #2
0
 public NodeTree(NodeTree son, NodeTree brother, int data, int x, int y) // конструктор
 {
     Son     = son;
     Brother = brother;
     Data    = data;
     X       = x;
     Y       = y;
 }
Beispiel #3
0
 public List <int> AllElements(NodeTree tr, List <int> elmnts)
 {
     for (NodeTree t = tr; t != null; t = t.Brother)
     {
         elmnts.Add(t.Data);
         if (t.Son != null)
         {
             AllElements(t.Son, elmnts);
         }
     }
     return(elmnts);
 }
Beispiel #4
0
 public void Insert(NodeTree tree, int data, bool isbrother)
 {
     if (isbrother)
     {
         Widht++;
         tree.Brother = new NodeTree(null, null, data, Widht, Height);
     }
     else
     {
         Widht    = tree.X;
         Height   = tree.Y + 1;
         tree.Son = new NodeTree(null, null, data, Widht, Height);
     }
 }
Beispiel #5
0
        public void Add(NodeTree tree, int data, int treeanchor, bool isbrother)  // вставка
        {
            tree = Search(treeanchor, tree);
            if (tree == null)
            {
                Top = new NodeTree(null, null, data, Widht, Height);
                Height++;
            }

            else if (treeanchor == Convert.ToInt32(tree.Data))
            {
                Insert(tree, data, isbrother);
            }
        }
Beispiel #6
0
 public NodeTree Search(int val, NodeTree tr)
 {
     if (tr == null)
     {
         return(null);
     }
     else
     {
         if (tr.Data == val)
         {
             return(tr);
         }
         return(SearchingRecursion(tr, val));
     }
 }
Beispiel #7
0
 public List <int> NodeTreeWithoutSons(NodeTree tr, List <int> elmnts)
 {
     for (NodeTree t = tr; t != null; t = t.Brother)
     {
         if (t.Son == null)
         {
             elmnts.Add(t.Data);
         }
         else
         {
             NodeTreeWithoutSons(t.Son, elmnts);
         }
     }
     return(elmnts);
 }
Beispiel #8
0
 public NodeTree SearchingRecursion(NodeTree tr, int val)
 {
     if (tr.Data == val)
     {
         Tmp = tr;
     }
     for (NodeTree t = tr; t != null; t = t.Brother)
     {
         if (t.Son != null)
         {
             if (t.Data == val)
             {
                 Tmp = t;
             }
             SearchingRecursion(t.Son, val);
         }
         if (t.Brother != null)
         {
             SearchingRecursion(t.Brother, val);
         }
     }
     return(Tmp);
 }