-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTree.php
More file actions
31 lines (26 loc) · 804 Bytes
/
BinaryTree.php
File metadata and controls
31 lines (26 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once 'Node.php';
//Copyright Christopher Thomas 2003 (cst at andrew dot cmu dot edu)
//You may use and redistribute freely as long as you keep this copyright
//notice. Feel free to modify as you want
class BinaryTree {
public $root;
function BinaryTree() {
$this->root = null;
}
function search($key) {
if ($this->root == null) {
return false;
}
return $this->root->search($key);
}
function addItem($item, $indexField = 'id') {
if ($this->root == null) {
$this->root = new Node();
$this->root->data[] = $item;
$this->root->index = $item[$indexField];
return true;
}
return $this->root->addItem($item[$indexField], $item);
}
}