使用php mysql在二叉树中查找插入位置和子节点数

使用php mysql在二叉树中查找插入位置和子节点数,第1张

使用php mysql在二叉树中查找插入位置和子节点
function getNodeInsertPostionByParentId($parentId){        $position = array('status'=>false);        $parents = array();        foreach($parentId as $parent){        $qry = "select customer_id,node_direction from mlm_nodes where parent_id =".$parent." order by node_direction";     $rst = mysql_query($qry);     $count = mysql_num_rows($rst);     if($count==2){         while($row = mysql_fetch_assoc($rst)){  $parents[$parent][] = $row['customer_id'];         }        }elseif($count==1){         $position['status'] = true;         $position['parentId'] = $parent;         $position['node'] = 'R';         //echo '<pre>1';print_r($position);echo '</pre>';         return $position;     }else{         $position['status'] = true;         $position['parentId'] = $parent;         $position['node'] = 'L';         //echo '<pre>2';print_r($position);echo '</pre>';         return $position;     } }        return $this->searchByParents($parents);    }    function searchByParents($parents){        foreach($parents as $parent){ return $this->getNodeInsertPostionByParentId($parent);          }    } echo '<pre>';print_r($this->getNodeInsertPostionByParentId(array('4')));die;


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5003750.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存