I’m writing a Ruby script and would like to use a n-ary tree data structure.
Is there a good implementation that is available as source code? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To expand on Otto’s answer, an easy way of getting a Hash to auto-vivify arrays is to use the default value block with
Hash::new, like so:But really, the code depends on what you want to do with your arrays. You can either set them up with Hashes and Arrays, or make some classes:
This code, for example, gives: