mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibHTML: Add TreeNode::next_in_pre_order()
This function allows you to traverse in pre-order without recursing.
This commit is contained in:
parent
17752b2973
commit
1466a7364c
1 changed files with 20 additions and 0 deletions
|
@ -53,6 +53,26 @@ public:
|
||||||
|
|
||||||
bool is_child_allowed(const T&) const { return true; }
|
bool is_child_allowed(const T&) const { return true; }
|
||||||
|
|
||||||
|
T* next_in_pre_order()
|
||||||
|
{
|
||||||
|
if (first_child())
|
||||||
|
return first_child();
|
||||||
|
T* node;
|
||||||
|
if (!(node = next_sibling())) {
|
||||||
|
node = parent();
|
||||||
|
while (node && !node->next_sibling())
|
||||||
|
node = node->parent();
|
||||||
|
if (node)
|
||||||
|
node = node->next_sibling();
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* next_in_pre_order() const
|
||||||
|
{
|
||||||
|
return const_cast<TreeNode*>(this)->next_in_pre_order();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
IterationDecision for_each_in_subtree(Callback callback) const
|
IterationDecision for_each_in_subtree(Callback callback) const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue