| Conditions | 8 |
| Paths | 8 |
| Total Lines | 36 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function insert($node) //$node is a treenode |
||
| 23 | { |
||
| 24 | $this->validate_parameter($node); |
||
| 25 | |||
| 26 | if($this->root == null) |
||
| 27 | { |
||
| 28 | $this->root = $node; |
||
| 29 | return $this; |
||
| 30 | } |
||
| 31 | |||
| 32 | $n = $this->root; |
||
| 33 | while(1) |
||
| 34 | { |
||
| 35 | if($node->value < $n->value) |
||
| 36 | { |
||
| 37 | if($n->left == null) |
||
| 38 | { |
||
| 39 | $n->left = $node; |
||
| 40 | return $this; |
||
| 41 | } |
||
| 42 | |||
| 43 | $n = $n->left; |
||
| 44 | } |
||
| 45 | else if($node->value > $n->value) |
||
| 46 | { |
||
| 47 | if($n->right == null) |
||
| 48 | { |
||
| 49 | $n->right = $node; |
||
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | $n = $n->right; |
||
| 54 | } |
||
| 55 | else if($node->value == $n->value) //node is already in the tree, we do not create duplicates! |
||
| 56 | { |
||
| 57 | return $this; |
||
| 58 | } |
||
| 105 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.