Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: how to construct tree from parent pointer listby demerphq (Chancellor) |
on Mar 22, 2006 at 17:50 UTC ( [id://538557]=note: print w/replies, xml ) | Need Help?? |
This is an algorithm that IMO every programmer should be familiar with. Its good that you are taking the time to learn.
This version of the algorithm is flexible, it doesnt expect the nodes to be inorder as some of the solutions posted do. It will also identify mixed heirarchies (ie two distinct trees in the same list), and is fairly simple. It has the disadvantage that it must store a list of the nodes which are children until the end of the data input. Here is the output:
--- $world=~s/war/peace/g
In Section
Seekers of Perl Wisdom
|
|