Picture a File Explorer-style window with the folders fully expanded. Starting at an arbitrary node, I press the down arrow to move down through the tree. Maybe I'm reading it wrong but I couldn't find a name for this kind of traversal (note: this article only applies to binary trees; I can't find a good reference on N-ary traversals and their names).
In my code I've struggled to find a good name for this. I've used GetForwardEnumerator()
, GetNextNode()
, etc. The closest I can come to expressing this is that it's the "next node in the tree", but that only makes sense if you look at the tree like a file explorer window as I've described.
What's the standard name for this kind of traversal/enumeration, and how might I name methods and properties that perform it? For now I'm settling for .NextNode
. It's uncomfortably close to .NextSibling
, but it's the best way I've found to communicate the intent.
Sample code:
/// <summary>
/// Gets the next node.
/// </summary>
/// <value>
/// The next tree node if it exists; otherwise, <c>null</c>.
/// </value>
public SimpleTreeNode<T> NextNode
{
get
{
if (this.Children.Count > 0)
{
return this.Children[0];
}
else if (this.NextSibling != null)
{
return this.NextSibling;
}
else
{
SimpleTreeNode<T> parentNode = this.Parent;
while (parentNode != null)
{
SimpleTreeNode<T> nextSiblingNode = parentNode.NextSibling;
if (nextSiblingNode != null)
{
return nextSiblingNode;
}
parentNode = parentNode.Parent;
}
}
return null;
}
}