表结构和表数据就不公示了,查询的表user_role,主键是id,每条记录有parentid字段; 如下mysql查询函数即可实现根据一个节点查询所有的子节点,根据一个子节点查询所有的父节点.对于数据量较大的时候(我这里测试的1万条左右).查询效率非常慢.建议在java代码中进行处理. CREATE FUNCTION `getChildList`(rootId INT) ) BEGIN ); ); SET sChildTemp =cast(rootId as CHAR); WHILE sChil
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q