Алгоритм удаления узлов из дерева - C#
Формулировка задачи:
В общем, нужна программа для работы с деревом
Подскажите как сделать удаление узлов
Например при удалении - "1" автоматически удаляются элементы "12, 121 и 122"
Как лучше организовать класс для работы с фигурами? В общем жду ваших подсказок
Решение задачи: «Алгоритм удаления узлов из дерева»
textual
Листинг программы
public decimal ScaleCoefficient
{
get { return scaleCoefficient; }
set
{
foreach(Node fst in AllNodes()) {
fst.between = (int)(Math.Round(NormalBetween * value));
fst.scaledHorizontalDistance = (int)(Math.Round(fst.normalHorizontalDistance * value));
fst.scaledverticalDistance = (int)(Math.Round(fst.normalVerticalDistance * value));
int newwidth = (int)(Math.Round(NormalSize.Width * value)), newheigth = (int)(Math.Round(NormalSize.Height * value));
if (fst.Parent != null)
{
var p2 = new Point(fst.Parent.Rect.Left + fst.Parent.Rect.Width / 2, fst.Parent.Rect.Bottom);
var p1 = new Point(p2.X, p2.Y + fst.Parent.scaledverticalDistance);
switch (fst.Parent.ChildrenOrientation)
{
case ChildrenOrientation.Horizontal:
{
int index = fst.Parent.Children.IndexOf(fst);
int indplpos = index - fst.Parent.Children.Count / 2 + fst.Parent.correction;
Point p3 = new Point(p1.X + (newwidth * (indplpos)) + fst.Parent.scaledHorizontalDistance * indplpos, p1.Y);
var p4 = new Point(p3.X, p3.Y + fst.between);
fst.Rect = new Rectangle(p4.X - newwidth / 2, p4.Y, newwidth,newheigth);
}
break;
case ChildrenOrientation.Vertical:
{
Point p3 = new Point(p1.X - newwidth / 2 - fst.between, p1.Y);
Point p4 = new Point(p3.X, p3.Y + newheigth / 2 + fst.between * (fst.Parent.Children.IndexOf(fst) + 1) + newheigth * fst.Parent.Children.IndexOf(fst));
Point p5 = new Point(p3.X + fst.between, p4.Y);
fst.Rect = new Rectangle(p3.X + fst.between, p4.Y - fst.Rect.Height / 2, newwidth, newheigth);
}
break;
}
}
else
{
fst.Rect = new Rectangle(fst.Rect.Left,fst.Rect.Top, newwidth,newheigth);
}
fst.scaleCoefficient = value;
}
scaleCoefficient = value;
}
}