Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Node<T>
- {
- public Node(T value)
- {
- this.Value = value;
- this.Children = new List<Node<T>>();
- }
- public T Value { get; set; }
- public List<Node<T>> Children { get; private set; }
- public void PrintTree()
- {
- Console.WriteLine("Tree");
- this.Print(string.Empty, true);
- }
- private void Print(string prefix, bool isTail)
- {
- Console.WriteLine(prefix + (isTail ? "└── " : "├── ") + this.Value);
- for (int i = 0; i < this.Children.Count - 1; i++)
- this.Children[i].Print(prefix + (isTail ? " " : "│ "), false);
- if (this.Children.Count >= 1)
- this.Children[this.Children.Count - 1].Print(prefix + (isTail ? " " : "│ "), true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement