Example #1
0
        public void FullBalancedBST()
        {
            var target = new BSTFlatteningProblem();

            Node root = new Node()
            {
                Value = 4
            };

            root.Left = new Node()
            {
                Value = 2
            };
            root.Right = new Node()
            {
                Value = 6
            };

            root.Left.Left = new Node()
            {
                Value = 1
            };
            root.Left.Right = new Node()
            {
                Value = 3
            };

            root.Right.Left = new Node()
            {
                Value = 5
            };
            root.Right.Right = new Node()
            {
                Value = 7
            };

            target.TransformSortedList(ref root);

            var next = root;

            for (int i = 1; i < 8; i++)
            {
                Assert.AreEqual(i, next.Value);
                next = next.Right;
            }

            Assert.IsNull(next);
        }
Example #2
0
        public void BoundaryBST()
        {
            var target = new BSTFlatteningProblem();

            Node root = new Node()
            {
                Value = 1
            };

            target.TransformSortedList(ref root);

            var next = root;

            for (int i = 1; i < 2; i++)
            {
                Assert.AreEqual(i, next.Value);
                next = next.Right;
            }

            Assert.IsNull(next);
        }