PHP - Recursive binary tree -
i've been having fun php trying explore potentials tried see if can implement binary tree structure. here code:
class node{ public $leftnode; public $rightnode; public $value; public function node($value){ $this->value = $value; } } class bintree{ public function inserter(node $node, $value){ if($value < $node->value){ if($node->leftnode != null){ inserter($node, $value); } else{ $node->leftnode = new node($value); } } else if($value > $node->value){ if($node->rightnode != null){ inserter($node, $value); } else{ $node->rightnode = new node($value); } } } }
now reason, when try call inserter function within (i.e. inserter ($node, $value), error: fatal error: call undefined function inserter().
tried referencing via $this , bintree:: no luck. fatal error: using $this when not in object context
, fatal error: allowed memory size of 134217728 bytes exhausted
errors respectively. can explain happening?
i suspect problem following:
php constructor works way
public function __construct () { }
(vs c# syntax using)