当前位置: 首页>>代码示例>>PHP>>正文


PHP Tree::insert方法代码示例

本文整理汇总了PHP中Tree::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Tree::insert方法的具体用法?PHP Tree::insert怎么用?PHP Tree::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preorder

            } else {
                $this->left->insert($n);
            }
        }
    }
}
$t = new Tree('F');
$n1 = new Tree('B');
$n2 = new Tree('G');
$n3 = new Tree('A');
$n4 = new Tree('D');
$n5 = new Tree('C');
$n6 = new Tree('E');
$n7 = new Tree('I');
$n8 = new Tree('H');
$t->insert($n1);
$t->insert($n2);
$t->insert($n3);
$t->insert($n4);
$t->insert($n5);
$t->insert($n6);
$t->insert($n7);
$t->insert($n8);
function preorder($tree)
{
    if (!$tree->left && !$tree->right) {
        return $tree;
    }
    if ($tree->left) {
        echo $tree->left->key, " ";
        preorder($tree->left);
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:31,代码来源:preorder_traversal.php

示例2: search

 public static function search($node, $main_buss_id)
 {
     if ($node === NULL || $node === "" || $main_buss_id === NULL || $main_buss_id === "") {
         QconfMgrLog::err(__FILE__, __LINE__, "node_id or main_buss_id is NULL");
         return FALSE;
     }
     ArgsUtil::setSQLEscape($node);
     ArgsUtil::setSQLEscape($main_buss_id);
     $query = "select * from qconf_node where main_buss_id = '{$main_buss_id}'" . " and node like '%{$node}%' order by node_whole";
     $res = self::executeQuery($query);
     if ($res === FALSE) {
         return FALSE;
     }
     // not found the node
     $num = mysql_num_rows($res);
     if ($num === 0) {
         return FALSE;
     }
     $tree = new Tree();
     while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
         $tree->insert($row['node_id'], $row['parent_node_id'], $row);
         $p_row = $row;
         while ($p_row['parent_node_id'] != 0) {
             $query = "select * from qconf_node where node_id = '" . $p_row['parent_node_id'] . "'";
             $p_res = self::executeQuery($query);
             if ($p_res === FALSE) {
                 return FALSE;
             }
             $p_row = mysql_fetch_array($p_res, MYSQL_ASSOC);
             $tree->insert($p_row['node_id'], $p_row['parent_node_id'], $p_row);
         }
     }
     return $tree->getTree();
 }
开发者ID:sdgdsffdsfff,项目名称:qconf-inner,代码行数:34,代码来源:NodeServ.php

示例3: insertByArray

 /**
  * 增加一条路由规则
  * @param array $paths
  * @param array $params
  * @param mixed $e
  * @return boolean
  */
 public function insertByArray($paths, $params, $e)
 {
     //生成树形的路由表,便于快速查找,
     // 如 规则
     //  "/b/a?z=1&y=2" => service1
     //  "/b/a?z=1&x=2" => service2
     //  对应的 规则结构是
     // path ->  a+
     //           |-b+
     // param ->    |-x+
     //             	  |-z   => service2
     //             |-y+
     //                |-z   => service1
     //
     //
     //
     $paths = array_filter($paths, function ($i) {
         return !empty($i);
     });
     array_unshift($paths, '/');
     if (empty($paths)) {
         $paths = array('');
     }
     if ($params !== null) {
         //排序,使参数与顺序无关
         sort($params, SORT_STRING);
         $params = array_filter($params, function ($i) {
             return !empty($i);
         });
         $node = $this->routes->findNode($paths, true, true);
         if ($node && $node['value'] instanceof \phprs\util\Tree) {
             $route = $node['value'];
             return $route->insert($params, $e, false);
         } else {
             $route = new Tree();
             $route->insert($params, $e, false);
             return $this->routes->insert($paths, $route, false);
         }
     } else {
         return $this->routes->insert($paths, $e, false);
     }
 }
开发者ID:caoym,项目名称:phprs-restful,代码行数:49,代码来源:HttpRouterEntries.php

示例4: find_common

            if ($this->left == null) {
                // insert
                $this->left = $n;
                $n->parent = $this;
            } else {
                $this->left->insert($n);
            }
        }
    }
}
$t = new Tree(10);
$n1 = new Tree(20);
$n2 = new Tree(5);
$n3 = new Tree(7);
$n4 = new Tree(13);
$t->insert($n1);
$t->insert($n2);
$t->insert($n3);
function find_common($node1, $node2, $tree)
{
    if ($node1->key < $tree->key && $node2->key > $tree->key) {
        return $tree;
    } else {
        if ($node1->key < $tree->key && $node2->key < $tree->key) {
            find_common($node1, $node2, $tree->left);
        } else {
            if ($node1->key > $tree->key && $node2->key > $tree->key) {
                find_common($node1, $node2, $tree->right);
            }
        }
    }
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:31,代码来源:lca_2.php


注:本文中的Tree::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。