Esempio n. 1
0
function makeTree($db, $name, $level = 2)
{
    $node = makeNode($name);
    if ($level > 0) {
        $cl = getContacts($db, $name);
        foreach ($cl as $c) {
            $node["children"][] = makeTree($db, $c["name"], $level - 1);
        }
    }
    return $node;
}
Esempio n. 2
0
<?php

/**
 * @author:wusuopubupt
 * @date  :2013-10-08
 * @language: php
 * Binary Search Tree  
 */
$nums = array(6, 3, 9, 5, 1, 7, 2, 8, 4);
$node = makeNode();
buildBinaryTree($node, $nums);
print_r($node);
delete($node, 3);
print_r($node);
function buildBinaryTree(&$node, $nums)
{
    foreach ($nums as $num) {
        insert($node, $num);
    }
}
function makeNode($root = NULL, $left = NULL, $right = NULL)
{
    $node = array();
    $node['root'] = $root;
    $node['left'] = $left;
    $node['right'] = $right;
    return $node;
}
function insert(&$node, $obj)
{
    if ($node['root'] == NULL) {