二叉树中的递归函数调用(recursive function call in binary tree)

编程入门 行业动态 更新时间:2024-10-25 12:27:51
二叉树中的递归函数调用(recursive function call in binary tree)

我有一个表ft_individual,它存储有关二进制树的信息,它包含属性Id,User_name,Active(表示用户是否有效),Position(L表示左,R表示右)和Father_id ....我想要获得特定用户左侧位置的孩子的数量,然后获得用户左侧位置的孩子的数量。

我做了一个递归函数调用,但它没有工作。 我正在使用PHP codeigniter框架工作......帮助

$l_count=$this->tree_model->childCount($user_i,'L'); $r_count=$this->tree_model->childCount($user_i,'R');

内部模型。

public function childCount($user_id='',$position='') { $this->db->select('id'); $this->db->from('ft_individual'); $this->db->where('father_id',$user_id); $this->db->where('position',$position); $this->db->where('active','yes'); $result=$this->db->get(); foreach ($result->result() as $row) { $id= $row->id; } if($id!='') { return (1+childCount($id,'L')+childCount($id,'R')); } else { return 1; } }

i have a table ft_individual which store information about a binary tree it comprises of attributes Id,User_name,Active(to represent user is active or not ),Position(L for left, R for right),and Father_id.... i want to get the number of child’s in left position of a particular user then the number of child’s in left position of a user.

i made a recursive function call but it is not working. I am using PHP codeigniter frame work......Help

$l_count=$this->tree_model->childCount($user_i,'L'); $r_count=$this->tree_model->childCount($user_i,'R');

inside model.

public function childCount($user_id='',$position='') { $this->db->select('id'); $this->db->from('ft_individual'); $this->db->where('father_id',$user_id); $this->db->where('position',$position); $this->db->where('active','yes'); $result=$this->db->get(); foreach ($result->result() as $row) { $id= $row->id; } if($id!='') { return (1+childCount($id,'L')+childCount($id,'R')); } else { return 1; } }

最满意答案

你应该调用函数childCount作为类的方法,只需添加$this->

return (1 + $this->childCount($id,'L') + $this->childCount($id,'R'));

You should call the function childCount as method of a class, just add $this->

return (1 + $this->childCount($id,'L') + $this->childCount($id,'R'));

更多推荐

本文发布于:2023-08-04 00:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   函数   二叉树   recursive   tree

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!