Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TonyFish

Composite Trees and Visitors

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m new to design patterns and I''m trying to design a simple pretty- printer for a tree structure. I already have a composite structure for my trees and was thinking of printing with a visitor system. I''d like the output to resemble the following: A +-B | +-Q +-E | +-T | | +-X | | +-Y | | +-Z | +-O +-W So far all I can get is the ordering: A B Q E T X Y Z O W Does anyone here have an idea of how I should proceed? Many Thanks <Fish>{

Share this post


Link to post
Share on other sites
Advertisement
I think you need to pass in an extra numeric parameter, which tracks how ''deep'' you are in the tree. Everytime you print the sub-elements of an element, increase it by one. When you print, use the number to say how many leading +--- to print.


-* Nostik
KQ lives

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!