-4

I want to print tree, which contains in a List<Node>. Anybody help me

Class Node has 4 fields:

    public char Symbol { get; set; }
    public int Frequency { get; set; }
    public Node Right { get; set; }
    public Node Left { get; set; }
  • we need more information, what do you want to print? – Fredou Dec 24 '14 at 23:52
  • 1
    You have three operations at your disposal: 1. Printing the left subtree 2. Printing the right subtree 3. Printing the symbol/frequency of the current node. The important decision in your exercise is to decide what order you should print those three things. Do it recursively for the trees. – Nicolas Louis Guillemot Dec 24 '14 at 23:52

3 Answers3

0

Tree traversal is probably the thing that you are interested in. You may read about it for example here. And if it is a typical Binary Search Tree then you should probably consider the In-Order tree walk to print the elements in an ascending order.

3yakuya
  • 2,622
  • 4
  • 25
  • 40
0

you need to tell us Breadth first or Depth first ? or some other ways to traversal the tree

Someone has already provide the solution of Breadth first here

Community
  • 1
  • 1
liuzhidong
  • 538
  • 3
  • 18
0

https://github.com/AharonSambol/PrettyPrintTreeCSharp

I know I'm late.. But I made this solution which works not only for simple trees but also for more complex ones (such as multi-lined strings)

Example output:

enter image description here