Beispiel #1
0
        public void TestOutput()
        {
            IList <int> sortedValues = new List <int> {
                15, 8, 7, 23, 15, 5, 9, -1, 27, 18, 15, 14, 12, 14, 27, 10, 32, 18, 42, -4, 8, 12, 9, 2, 0
            }.OrderBy(i => i).ToList();

            CollectionAssert.AreEquivalent(sortedValues.ToList(), tree.Output().ToList());
        }
        public IEnumerable <T> Output()
        {
            if (_left != null)
            {
                foreach (T t in _left.Output())
                {
                    yield return(t);
                }
            }
            yield return(_value);

            if (_right != null)
            {
                foreach (T t in _right.Output())
                {
                    yield return(t);
                }
            }

            // yield return lazy evaluates, e.g. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield
        }