/// <summary> /// "Prune" branches of this tree after the predicate returns false. /// </summary> /// <param name="pred">Pred.</param> public void Prune(Predicate <T> pred) { if (!pred(CurrentNode)) { Parent.Snip(); } else { LeftBranch.Prune(pred); RightBranch.Prune(pred); } }
/// <summary> /// Flattens the entire tree into a list of its Nodes. Working on these directly /// affects the information in the tree, so be careful. /// </summary> public List <T> Flatten() { if (RightBranch == null && LeftBranch == null) { return(TailHelper.Wrap(CurrentNode)); } else { return(TailHelper.Concatenate( // Returns the current node and all the other nodes TailHelper.Wrap(CurrentNode), TailHelper.Concatenate(RightBranch.Flatten(), LeftBranch.Flatten()))); } }