コード例 #1
0
        private IEnumerable <Tkey> TraverseNode(BinaryKeyValueNode <Tkey> node, DepthFirstTraversalMethod method)
        {
            IEnumerable <Tkey> TraverseLeft  = node.LeftChild == null ? new Tkey[0] : TraverseNode(node.LeftChild, method),
                               TraverseRight = node.RightChild == null ? new Tkey[0] : TraverseNode(node.RightChild, method),
                               Self          = new Tkey[1] {
                node.Key
            };

            switch (method)
            {
            case DepthFirstTraversalMethod.PreOrder:
                return(Self.Concat(TraverseLeft).Concat(TraverseRight));

            case DepthFirstTraversalMethod.InOrder:
                return(TraverseLeft.Concat(Self).Concat(TraverseRight));

            case DepthFirstTraversalMethod.PostOrder:
                return(TraverseLeft.Concat(TraverseRight).Concat(Self));

            default:
                throw new ArgumentException();
            }
        }
コード例 #2
0
 public IEnumerable <Tvalue> TraverseTree(DepthFirstTraversalMethod method)
 {
     return(TraverseNode(Root, method));
 }