Breadth-first threading

The solution of the task described in this article with O(n) time complexity and O(1) space complexity.

Correctness of this solution is demonstrated by comparing the results of the classic breadth-first tree traversal (using queue) with the breadth-first traversal using this type of threading.