为什么DOM树oder预订,深度优先遍历?
与其他遍历如BFT相比,此设计选择有哪些优势?
我只是在研究DOM standard并找到了前后的定义:
An object A is preceding an object B if A and B are in the same tree
and A comes before B in tree order.An object A is following an object B if A and B are in the same tree
and A comes after B in tree order.Just like most programming paradigms the Web platform has finite
hierarchical tree structures,simply named trees. The tree order is
preorder,depth-first traversal.
解决方法
深度优先遍历通常是最简单的遍历样式,因为您可以递归或使用显式堆栈执行此操作;广度优先需要一个队列,在某种意义上,这是一个更复杂的数据结构.但我认为答案比传统或简单更简单:(X)HTML树的深度搜索遍历导致文本节点以呈现顺序遍历.
考虑这个相对简单的HTML子树.
或者,以原始形式:
<p>Consider this <emph>relatively</emph> simple <a href="...">HTML</a> subtree</p>
作为一棵树(省略空白和属性):
<P> | +-----------+----+----+-----+------+ ______|______ __|___ ___|__ _|_ ___|___ Consider this <EMPH> simple <A> subtree | | ____|_____ __|__ relatively HTML
深度优先遍历:
<P>,Consider this,<EMPH>,relatively,simple,<A>,HTML,subtree
广度优先遍历:
<P>,subtree,HTML
原文地址:https://www.jb51.cc/js/154340.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。