SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | public class Node<T> | |
4 | { | |
5 | public Node(T value) | |
6 | { | |
7 | this.Value = value; | |
8 | this.Children = new List<Node<T>>(); | |
9 | } | |
10 | ||
11 | public T Value { get; set; } | |
12 | - | public List<Node<T>> Children { get; private set; } |
12 | + | public IList<Node<T>> Children { get; private set; } |
13 | ||
14 | public void PrintTree() | |
15 | { | |
16 | Console.WriteLine("Tree"); | |
17 | this.Print(string.Empty, true); | |
18 | } | |
19 | ||
20 | private void Print(string prefix, bool isTail) | |
21 | { | |
22 | Console.WriteLine(prefix + (isTail ? "└── " : "├── ") + this.Value); | |
23 | for (int i = 0; i < this.Children.Count - 1; i++) | |
24 | this.Children[i].Print(prefix + (isTail ? " " : "│ "), false); | |
25 | ||
26 | if (this.Children.Count >= 1) | |
27 | this.Children[this.Children.Count - 1].Print(prefix + (isTail ? " " : "│ "), true); | |
28 | } | |
29 | } |