예제 #1
0
 /**
  * Causes a visitor to visit the nodes of this tree
  * in depth-first traversal order starting from this node.
  * This method invokes the preVisit, inVisit
  * and postVisit methods of the visitor
  * for each node in this tree.
  *
  * @param object IPrePostVisitor $visitor The visitor to accept.
  */
 public function depthFirstTraversal(IPrePostVisitor $visitor)
 {
     if (!$this->isEmpty()) {
         for ($i = 0; $i <= $this->count; ++$i) {
             if ($i >= 2) {
                 $visitor->postVisit($this->key[$i - 1]);
             }
             if ($i >= 1 && $i <= $this->count) {
                 $visitor->inVisit($this->key[$i]);
             }
             if ($i <= $this->count - 1) {
                 $visitor->preVisit($this->key[$i + 1]);
             }
             if ($i <= $this->count) {
                 $this->subtree[$i]->depthFirstTraversal($visitor);
             }
         }
     }
 }
예제 #2
0
 /**
  * Causes a visitor to visit the nodes of this tree
  * in depth-first traversal order starting from this node.
  * This method invokes the preVisit, inVisit
  * and postVisit methods of the visitor
  * for each node in this tree.
  * @param object IPrePostVisitor $visitor The visitor to accept.
  */
 public function depthFirstTraversal(IPrePostVisitor $visitor)
 {
     if (!$this->isEmpty()) {
         $visitor->preVisit($this->key);
         $this->left->depthFirstTraversal($visitor);
         $visitor->inVisit($this->key);
         $this->right->depthFirstTraversal($visitor);
         $visitor->postVisit($this->key);
     }
 }
예제 #3
0
 /**
  * Recursive depth-first traversal method.
  *
  * @param object IPrePostVisitor $visitor The visitor to accept.
  * @param integer $start The vertex at which to start the traversal.
  * @param object BasicArray $visited
  * Used to keep track of the visited vertices.
  */
 private function doDepthFirstTraversal(IPrePostVisitor $visitor, $v, $visited)
 {
     if ($visitor->isDone()) {
         return;
     }
     $visitor->preVisit($v);
     $visited[$v->getNumber()] = true;
     foreach ($v->getSuccessors() as $to) {
         if (!$visited[$to->getNumber()]) {
             $this->doDepthFirstTraversal($visitor, $to, $visited);
         }
     }
     $visitor->postVisit($v);
 }
예제 #4
0
 /**
  * Causes a visitor to visit the nodes of this tree
  * in depth-first traversal order starting from this node.
  * This method invokes the preVisit
  * and postVisit methods of the visitor
  * for each node in this tree.
  * The default implementation is recursive.
  * The default implementation never invokes the InVisit method
  * of the visitor.
  * The traversal continues as long as the isDone
  * method of the visitor returns false.
  *
  * @param object IPrePostVisitor $visitor The visitor to accept.
  */
 public function depthFirstTraversal(IPrePostVisitor $visitor)
 {
     if ($visitor->isDone()) {
         return;
     }
     if (!$this->isEmpty()) {
         $visitor->preVisit($this->getKey());
         for ($i = 0; $i < $this->getDegree(); ++$i) {
             $this->getSubtree($i)->depthFirstTraversal($visitor);
         }
         $visitor->postVisit($this->getKey());
     }
 }