Example #1
0
 protected function order(AbstractBinaryTree $root = NULL)
 {
     $this->finalData[] = $root->getData();
     if ($root->getLeftChild() != NULL) {
         $this->order($root->getLeftChild());
     }
     $this->finalData[] = $root->getData();
     if ($root->getRightChild() != NULL) {
         $this->order($root->getRightChild());
     }
     $this->finalData[] = $root->getData();
 }
Example #2
0
 protected function order(AbstractBinaryTree $root = NULL)
 {
     $this->finalData[] = $root->getData();
     if ($root->getLeftChild() != NULL) {
         $this->order($root->getLeftChild());
     }
     $this->finalData[] = $root->getData();
     if ($root instanceof TernaryTree && $root->getMiddleChild() != NULL) {
         $this->order($root->getMiddleChild());
         $this->finalData[] = $root->getData();
     }
     if ($root->getRightChild() != NULL) {
         $this->order($root->getRightChild());
     }
     $this->finalData[] = $root->getData();
 }
 protected function order(AbstractBinaryTree $root = NULL)
 {
     while (!$this->stack->isEmpty() || $root != NULL) {
         if ($root != NULL) {
             $this->finalData[] = $root->getData();
             if ($root->getRightChild() != NULL) {
                 $this->stack->push($root->getRightChild());
             }
             $root = $root->getLeftChild();
         } else {
             $root = $this->stack->pop();
         }
     }
 }