Hey,
I'm building a tree (again), which kinda consists out of double linked lists...
Structure simplified:
Root: First = 1; Last = 5; Next = ; Previous = ; 1: First = 11; Last = 15; Next = 2; Previous = ; 2: First = 21; Last = 25; Next = 3; Previous = 1; ... 554: First = ; Last = ; Next = 555 ; Previous = 553; 555: First = ; Last = ; Next = ; Previous = 554;
This is what I currently use to get all child nodes starting from one specific point (being root or not)... again simplified :
push(@Children,$root->child_nodes); # could be push(@Children,$start_n +ode_id); too, any starting point... while(@Children) { $node = shift @Children; print $node,"->"; my $Node = Node->new($node); my $next = $Node->first; while ($next) { print $next,","; my $Child = Node->new($next); push(@Children,$next); $next = $Child->next(); } print "\n"; }
Output is something similar to:
1->11,12,13,14,15, 2->21,25, 3->31,35, 4->41,45, 5->51,55, 11->111,112,113,114,115 12-> 13-> 14-> 15-> ...
I'm not building a tree perse, the order in which I get child nodes is not important. I dont need to store all child node data, just the actual node IDs. There could be alot of child nodes, resources could get quite limited.

Are there any specific theories on running up a tree?

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

In reply to Growing exotic trees by Beatnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.