小编use*_*945的帖子

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

下面是我的表数据

+-------------+-----------+----------------+
| customer_id | parent_id | node_direction |
+-------------+-----------+----------------+
|           1 |         0 | T              |
|           2 |         1 | L              |
|           3 |         1 | R              |
|           4 |         2 | L              |
|           5 |         2 | R              |
|           6 |         4 | L              |
+-------------+-----------+----------------+
Which represents the following tree
                      1
                      |
                  ---------
                  |       |
                  2       3
                  |
               -------
               |     |  
               4     5
               |
             -----
             |
             6

我需要找到父ID的插入位置

例如:

1)如果父id为1则插入位置为root-3 position-L
2)如果parent_id为2则插入位置为root-4 …

php mysql

6
推荐指数
1
解决办法
1057
查看次数

标签 统计

mysql ×1

php ×1