public Bitmap DrawingAllTree(Tree tree) { bmp = new Bitmap(870, 430); g = Graphics.FromImage(bmp); DrawAllTree(tree); return bmp; }
public Tree(int data) { this.data = data; left = null; right = null; parent = null; }
private void Draw (Tree tree) { if (tree.Pictured == false) { if (tree.Parent==null) { DrawVertex(Convert.ToString(tree.Data), new Point(bmp.Size.Width / 2, 1)); tree.Pictured = true; tree.X = bmp.Size.Width / 2; tree.Y = 1; tree.wh = bmp.Size.Width / 2; } else if (tree.Data>tree.Parent.Data) { tree.wh = tree.Parent.wh / 2; DrawVertex(Convert.ToString(tree.Data), new Point(tree.Parent.X +tree.wh, tree.Parent.Y + 40)); tree.Pictured = true; tree.X = tree.Parent.X + tree.wh; tree.Y = tree.Parent.Y + 40; var pt1 = new Point(tree.Parent.X, tree.Parent.Y); var pt2 = new Point(tree.X, tree.Y); DrawArrows(pt1, pt2); } else { tree.wh = tree.Parent.wh / 2; DrawVertex(Convert.ToString(tree.Data), new Point(tree.Parent.X - tree.wh, tree.Parent.Y + 40)); tree.Pictured = true; tree.X = tree.Parent.X - tree.wh; tree.Y = tree.Parent.Y + 40; var pt1 = new Point(tree.Parent.X, tree.Parent.Y); var pt2 = new Point(tree.X, tree.Y); DrawArrows(pt1,pt2); } } else { if (tree.Left != null) { Draw(tree.Left); } if (tree.Right != null) { Draw(tree.Right); } } }
public void Add(int data) { var node = new Tree(data); // Если первый пустой if (this.data == 0 && this.left == null && this.right == null && this.parent == null) { this.data = data; count++; } else { // Если уже существует первый if (node.Data < this.Data) { if (this.Left == null) { this.Left = node; left.parent = this; count++; } else { left.Add(data); } } else if (node.Data > this.Data) { if (this.Right == null) { this.Right = node; Right.parent = this; count++; } else { right.Add(data); } } } }
public Tree() { left = null; right = null; parent = null; }
private void FindMin(Tree data, ref Tree node) { var temp = data; if (temp.left == null) { node = temp; } else { temp.FindMin(temp.left, ref node); } }
public void Delete(int data) { if (data < this.data) { this.left.Delete(data); } if (data > this.data) { this.right.Delete(data); } if (data == this.data) { // Нету детей if (this.right == null && this.left == null) { if (this.parent.left != null) { if (this.parent.left.data == data) this.parent.left = null; else this.parent.right = null; } else if (this.parent.right != null) { if (this.parent.right.data == data) this.parent.right = null; else this.parent.right = null; } else { } } // Нету детей с лева else if (this.left == null && this.right != null) { // тут ошибки, не правильно учтена одна сторона this.parent.right = this.right; this.right.parent = this.parent; } // Нету детей с права else if (this.right == null && this.left != null) { // тут ошибки, не правильно учтена одна сторона this.parent.left = this.left; this.left.parent = this.parent; } // есть оба дитя else { if (this.right.left == null&& this.parent!=null) { this.right.parent = this.parent; this.left.parent = this.right; this.parent.right = this.right; this.right.left = this.left; } else if (this.parent != null) { this.FindMin(this.right, ref node); this.data = node.data; node.parent.left = null; node = null; } else { this.FindMin(this.right, ref node); this.data = node.data; node.parent.right = null; node = null; } } } }
public Bitmap Drawing(Tree tree) { Draw(tree); return bmp; }
public void InOrder(Tree N) { if (N == null) { return; } else { N.Pictured = false; if (N.Left != null) { InOrder(N.Left); } if (N.Right != null) { InOrder(N.Right); } } }