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(); } }
public IEnumerable <Tvalue> TraverseTree(DepthFirstTraversalMethod method) { return(TraverseNode(Root, method)); }