Skip to content

Commit

Permalink
inOrderTraverse implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ideaguy3d committed Dec 9, 2019
1 parent 071e8bb commit 01d6c50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
35 changes: 33 additions & 2 deletions @cs/BinaryTree.php
Expand Up @@ -76,11 +76,15 @@ private function searchNode($node, $key) {
}

public function inOrderTraverse(\Closure $callback) {

$this->inOrderTraverseNode($this->root, $callback);
}

private function inOrderTraverseNode($node, $callback) {

if($node !== null) {
$this->inOrderTraverseNode($node->left, $callback);
$callback($node->key);
$this->inOrderTraverseNode($node->right, $callback);
}
}

public function preOrderTraverse(\Closure $callback) {
Expand All @@ -99,4 +103,31 @@ private function postOrderTraverseNode($node, $callback) {

}

/**
* Get the key with the lowest value
*
* @param $key
*/
public function min($key) {

}

/**
* Get the key w/the highest value
*
* @param $key
*/
public function max($key) {

}

/**
* Remove a node via its' key
*
* @param $key
*/
public function remove($key) {

}

} // END OF: class BinarySearchTree
8 changes: 8 additions & 0 deletions @cs/index.php
Expand Up @@ -18,7 +18,15 @@
$binaryTree->insert($v);
}

echo "\n----------------------------------------------------------------------\n";

$callback = function($value){
echo " [$value] ";
};

$binaryTree->inOrderTraverse($callback);

echo "\n----------------------------------------------------------------------\n";



Expand Down

0 comments on commit 01d6c50

Please sign in to comment.