Ejemplo n.º 1
0
 void TraversePostorder(BinaryTreeVisitDelegate <UserType> visitMethod, ref bool cancel,
                        BinaryNode <UserType> node)
 {
     if (node != null && !cancel)
     {
         TraversePostorder(visitMethod, ref cancel, node.Left);
         TraversePostorder(visitMethod, ref cancel, node.Right);
         if (!cancel)
         {
             visitMethod(node, ref cancel);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Traverses the binary tree calling a visit method on each node.
 /// </summary>
 /// <param name="visitMethod">A method to be called on each visited node.</param>
 /// <param name="traversalMode">Mode of traversal to perform.</param>
 public void Traverse(BinaryTreeVisitDelegate <UserType> visitMethod,
                      BinaryTreeTraversal traversalMode = BinaryTreeTraversal.Inorder)
 {
     if (visitMethod != null)
     {
         bool cancel = false;
         if (traversalMode == BinaryTreeTraversal.Inorder)
         {
             TraverseInorder(visitMethod, ref cancel, m_root);
         }
         else if (traversalMode == BinaryTreeTraversal.Preorder)
         {
             TraversePreorder(visitMethod, ref cancel, m_root);
         }
         else if (traversalMode == BinaryTreeTraversal.Postorder)
         {
             TraversePostorder(visitMethod, ref cancel, m_root);
         }
     }
 }