I am iterating a tree using Breadth first search and I want to check whenever the iteration goes to a lower level in the tree each time to display a message and that using a pseudo code. I don't want to use the classic while-for loops but instead I want one for loop that is commented with (traverse BFS) like I do below it:
PreviousNodeLevel ← null
for node in tree do //(traverse BFS)
if node ∈ children(PreviousNodeLevel) then // if the current node is a child of any element of PreviousNodeLevel
display message // next level of nodes reached
else if PreviousNodeLevel != null then
PreviousNodeLevel ← null // next the next level case
end if
PreviousNodeLevel.insert(node)
end for
Any idea if this pseudo-code is correct to adopt ?