How to make an IEnumerable of values of tree nodes?
问题 Consider the following class: class TreeNode { int value; public TreeNode l, r; public TreeNode(int value) { this.value = value; } public IEnumerable<int> sub_values() { if (l != null) foreach (int i in l.sub_values()) yield return i; if (r != null) foreach (int i in r.sub_values()) yield return i; yield return value; } } Each value is passed O(h) times, where h is the height of the tree. First, in yield return value; statement, then in yield return i; of each parent node. So, sub_values