There is no cycle. k is a global reach variable that can be accessed within Reconstruct(T) . This is just the current character array index (input string).
As explained in the question you referenced ( Design a tree with a preview ), For the correct algorithm, make the left-child number of the node, and then the right-child number. This is what you see in the true if section. If the current node is a leaf, L , then do not give it children and return to the calling function.
What this function does is follow the left edge of the tree, adding children to all nodes of N and not adding children to all nodes of L (aka leaves) until the line ends.
Edit: when the author of the pseudocode says T.left = T.right = null , it means that at the moment the current node does not have a left or right child (because it is a sheet). This is just a statement and does not have to be in code.
Puddingfox
source share