I have spent some time trying to make a function to loop through nodes inserting childs, and after that I understand some of the reasons why looping through nodes is so difficult. My conclusions are:
- Since the position "p" of a node, right now, offers no more information than the position on a tree which will disappear if the tree changes, we might as well set the position value to be the actual numbered position that node occupies in the tree.
This way we don't loose any information or functionality from the nodes position reference, but instantly win a reference, since users will be able to call nodes by their position on the tree, even if the tree changes (When the tree changes we will obviously be calling the new node which occupies that position).
- What I'm asking for is just a way to reference and call actual position on the tree, by number,regardless of what has happened before or after or which node is there, just go to the "nth" node in the tree, but without having to loop through all the tree for that.
This would make possible:
- Simple loops through the tree while editing it, since the user would be able to "calculate" the absolute position of the nodes he wants edited
- Deletenodesinlist would instantly work through this approach (If our list to delete is position [3,4,8], the function will delete nodes by position [3,3,6], each time a node is deleted, all the numbers on the list must be substracted 1)
Double loops are infernal right now, because you have to consider:
- When a node changes, all the positions will change
- If then there is a loop within the loop, after a node changed, there is no way to keep reference in both loops (there is, we can make a list, but then we would need another list in case of 3rd concatenated loop, another in 4rth, etc etc) Not practical.
But again, I think this approach would also make those loops simpler.