private void RecIterate(Node <T> current, ProcessData <T> pd, TraversalOrder to) { if (to == TraversalOrder.PRE_ORDER) { pd(current.Data); } if (current.Left != null) { RecIterate(current.Left, pd, to); } if (to == TraversalOrder.IN_ORDER) { pd(current.Data); } if (current.Right != null) { RecIterate(current.Right, pd, to); } if (to == TraversalOrder.POST_ORDER) { pd(current.Data); } }
protected void InternalDepthFirstTraversal(BNode <T> start, TraversalOrder order, Action <BNode <T> > cb, bool includeNulls) { if (start == null) { if (includeNulls) { cb(null); } return; } if (order == TraversalOrder.Pre) { cb(start); } InternalDepthFirstTraversal(start.Left, order, cb, includeNulls); if (order == TraversalOrder.In) { cb(start); } InternalDepthFirstTraversal(start.Right, order, cb, includeNulls); if (order == TraversalOrder.Post) { cb(start); } }
public override void Iterate(ProcessData <T> pd, TraversalOrder to) { if (nRoot != null) { RecIterate(nRoot, pd, to); } }
public string PrettyStringTree(RbNode node, TraversalOrder order) { string output; switch (order) { case TraversalOrder.PreOrder: output = PrettyStringTreePreOrder(Root); break; case TraversalOrder.InOrder: output = PrettyStringTreeInOrder(Root); break; case TraversalOrder.OutOrder: output = PrettyStringTreeOutOrder(Root); break; case TraversalOrder.PostOrder: output = PrettyStringTreePostOrder(Root); break; default: throw new ArgumentException($"Could not get pretty string for tree with Id={Id} because traversal order had unexpected value."); } return(output); }
public static string TraversalOrderToString(TraversalOrder order) { switch (order) { case TraversalOrder.Preorder: return("preorder"); case TraversalOrder.Postorder: return("postorder"); case TraversalOrder.PreorderExpander: return("preorder-expander"); default: throw new InvalidOperationException($"TraversalOrder {order} binding not found, this is a client bug"); } }
/// <summary> /// Initializes a new instance of the <see cref="BinarySearchTree{T}"/> class. /// </summary> /// <param name="order">Order of traversal.</param> public BinarySearchTree(TraversalOrder order = TraversalOrder.PreOrder, Comparison <T> customComparison = null) { this.TraversalOrder = order; Comparison <T> myComparison; if (customComparison is null) { myComparison = GetStandardComparison; } else { myComparison = customComparison; } this.myComparer = Comparer <T> .Create(myComparison); }
public IList<int> Traversal(TraversalOrder traversalOrder = TraversalOrder.Straight) { var list = new List<int>(); if (traversalOrder == TraversalOrder.Straight) { if (_left != null) list.AddRange(_left.Traversal()); list.Add(_data.Value); if (_right != null) list.AddRange(_right.Traversal()); } else if (traversalOrder == TraversalOrder.Reverse) { if (_left != null) list.AddRange(_left.Traversal()); list.Add(_data.Value); if (_right != null) list.AddRange(_right.Traversal()); } return list; }
public readonly bool MoveNext <TCollection>( TCollection blocks, ref TraversalEnumerationState state) where TCollection : IReadOnlyList <BasicBlock> => TraversalOrder.ForwardsMoveNext(blocks, ref state);
public readonly TraversalEnumerationState Init <TCollection>(TCollection blocks) where TCollection : IReadOnlyList <BasicBlock> => TraversalOrder.ForwardsInit();
public string PrettyStringTree(TraversalOrder order) { return(PrettyStringTree(Root, order)); }
public void DisplayTree(RbNode node, TraversalOrder order) { Console.WriteLine(PrettyStringTree(node, order)); }
public void DisplayTree(TraversalOrder order) { Console.WriteLine(PrettyStringTree(order)); }
public virtual void DepthFirstTraversal(TraversalOrder order, Action <BNode <T> > cb, bool includeNulls = false) { InternalDepthFirstTraversal(Root, order, cb, includeNulls); }