Archived

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

TonyFish

Composite Trees and Visitors

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
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