Ejemplo n.º 1
0
        public IBinaryTree <T> BuildTree(List <T> nodeValues, BinaryTreeType type)
        {
            if (nodeValues == null || nodeValues.Count == 0)
            {
                return(null);
            }
            var nodes = new List <IBinaryTreeNode <T> >();
            var depth = 0;

            foreach (var value in nodeValues)
            {
                nodes.Add(_nodeProvider.GetBinaryTreeNode(value));
            }
            IBinaryTreeNode <T> root = null;

            switch (type)
            {
            case BinaryTreeType.Complete:
            {
                root = BuildCompleteTree(nodes);
                break;
            }

            case BinaryTreeType.Search:
            {
                root = BuildSearchTree(nodes);
                break;
            }
            }
            root.Type = BinaryTreeNodeType.Root;
            GetDepth(root, ref depth);
            return(new BinaryTree <T>(root, nodes.Count, depth, type));
        }