Home  >  Article  >  Database  >  06. 父子节点(树)遍历写法小结

06. 父子节点(树)遍历写法小结

WBOY
WBOYOriginal
2016-06-07 17:40:441253browse

对于树/图的遍历,通常有2种算法来实现:迭代(Iteration)和递归(Recursion),迭代是利用循环反复取值/赋值的过程;递归则是反复自己调用自己来获得最终结果。 SQL Server里的递归有32层嵌套限制,目的在于防止代码进入死循环,除非使用提示OPTION (MAXRECURS

对于树/图的遍历,香港服务器租用,通常有2种算法来实现:迭代(Iteration)和递归(Recursion),网站空间,迭代是利用循环反复取值/赋值的过程;递归则是反复自己调用自己来获得最终结果。
SQL Server里的递归有32层嵌套限制,目的在于防止代码进入死循环,除非使用提示OPTION (MAXRECURSION 0)。

测试数据:

) city city ( id int, name nvarchar(10), pid int, depth int ) city ,,N,,N,,N,,N,,N,,N,,N,,N,,N,,N,9,2 ,香港空间

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn