Two versions of breadth-first numbering a binary tree

As I said, I won't spoil the fun by giving you the code (try it yourself). But on this page, you can see the animated observations of two slightly different solutions to Okasaki's breadth-first numbering problem, demonstrating drastically different strictness properties. To recall the problem: Given a binary tree with numbers at the nodes, produce a structurally identical tree in which each node is numbered with its index in a breadth-first traversal.

Version 1.

Version 2.

The central idea in both versions is to use a task pool (a structure storing things to do). In version 1, new and processed tasks are stored in the same order (this makes managing the pool slightly "ugly"). In version 2, having seen a similar solution in Okasaki's paper, I adopted the trick to maintain results in reversed order (this leads to "nicer", slightly simpler code).

Note that at the end, both versions deliver the same result, and have observed the same parts of their parameters. They only differ in the order in which they observe their parameters and generate observable results.

Of course, my first solution was uglier than version 1 here, and had the behaviour of version 2 here, but that is another story..