Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How do "you" make a tree in perl

by FoxtrotUniform (Prior)
on Sep 29, 2004 at 02:22 UTC ( [id://394824]=note: print w/replies, xml ) Need Help??


in reply to How do "you" make a tree in perl

If you want to be "tricky", you can pack a binary heap into a one-dimensional list:

my $heap = ['Root', 'Child1', 'Child2', 'Grandchild1', Grandchild2'];

See heapsort for a stereotypical use of binary heaps. They're not as general as n-ary trees (being strictly binary and left-balanced), but they might make an interesting example.

For further fun and games with low-level-hacking data structures, pack a binheap into a string, with either null-separated or fixed-width fields:

# "\0" is a null, right? my $ns_heap = "R\0C1\0C2\0GC1\0GC2\0"; my $fw_heap = "R\0\0C1\0C2\0GC1GC2";
Again, this is almost gratuitously ugly, but might make a "fun" example.

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry

Replies are listed 'Best First'.
Re^2: How do "you" make a tree in perl
by stvn (Monsignor) on Sep 29, 2004 at 02:51 UTC

    I think that you and I tend to have somewhat similar ideas of "fun". However, this is a little more esoteric then I was looking for ;-)

    -stvn
      (T)his is a little more esoteric then I was looking for ;-)

      That shows good sense.

      On the subject of heaps, it would be neat to see a ->heapify method of some sort, especially if you supported binomial and/or fibonacci heaps (which are algorithmically very cool). That wouldn't be very ::Simple, but it might be useful (and fun to implement).

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me
      % man 3 strfry

        That wouldn't be very ::Simple, but it might be useful (and fun to implement).

        I think this is a perfect canidate for a Visitor object actually. If you care to contribute some code, I am always open to submissions :-)

        -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found