Я пытаюсь улучшить производительность в нашем приложении. У меня есть информация о производительности в виде дерева вызовов со следующим классом node:
public class Node
{
public string Name; // method name
public decimal Time; // time spent in method
public List<Node> Children;
}
Я хочу распечатать дерево, чтобы я мог видеть строки между узлами - что-то вроде этого вопроса. Какой алгоритм я могу использовать в С# для этого?
Изменить: Очевидно, мне нужно использовать рекурсию, но мои попытки продолжают помещать строки в неправильные места. То, что я прошу, - это конкретный алгоритм, который будет красиво печатать дерево - подробности о том, когда печатать вертикальную линию и когда печатать горизонтальную.
Изменить: Недостаточно просто использовать копии строки для отступов узлов. Я не ищу
A
|-B
|-|-C
|-|-D
|-|-|-E
|-F
|-|-G
он должен быть
A
+-B
| +-C
| +-D
| +-E
+-F
+-G
или что-нибудь подобное, если видна древовидная структура. Обратите внимание, что C и D имеют разные отличия от G - я не могу просто использовать повторяющуюся строку для отступов узлов.