But how can I print this tree like this:
23 1,45 -,2 | 31,52 -,- | -,3 | -,- | -,234 -,- | -,- | -,- | -,5 | -,- | -,- | -,- | -,- At the last two line it is necessary to print null subtree of a null subtree by "-"
My first go at it would be to mirror any old tree traversal with a sparse matrix that's sized to assume a full tree. If the height of the tree is 5, like your example, the sparse matrix would be initialized to a null subtree character and look like this.
[-]
[-][-]
[-][-][-][-]
[-][-][-][-][-][-][-][-]
[-][-][-][-][-][-][-][-][-][-][-][-][-][-][-][-] Then you do say an inorder traversal on the tree and also use cursors for the matrix that match the same position in the tree. You want the updates to look like this.
[<strong>23</strong>]
[-][-]
[-][-][-][-]
[-][-][-][-][-][-][-][-]
[-][-][-][-][-][-][-][-][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][-]
[-][-][-][-]
[-][-][-][-][-][-][-][-]
[-][-][-][-][-][-][-][-][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][-]
[-][<strong>2</strong>][-][-]
[-][-][-][-][-][-][-][-]
[-][-][-][-][-][-][-][-][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][-]
[-][<strong>2</strong>][-][-]
[-][-][-][<strong>3</strong>][-][-][-][-]
[-][-][-][-][-][-][-][-][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][-]
[-][<strong>2</strong>][-][-]
[-][-][-][<strong>3</strong>][-][-][-][-]
[-][-][-][-][-][-][-][<strong>5</strong>][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][<strong>45</strong>]
[-][<strong>2</strong>][-][-]
[-][-][-][<strong>3</strong>][-][-][-][-]
[-][-][-][-][-][-][-][<strong>5</strong>][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][<strong>45</strong>]
[-][<strong>2</strong>][<strong>31</strong>][-]
[-][-][-][<strong>3</strong>][-][-][-][-]
[-][-][-][-][-][-][-][<strong>5</strong>][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][<strong>45</strong>]
[-][<strong>2</strong>][<strong>31</strong>][-]
[-][-][-][<strong>3</strong>][-][234][-][-]
[-][-][-][-][-][-][-][<strong>5</strong>][-][-][-][-][-][-][-][-]
[<strong>23</strong>]
[<strong>1</strong>][<strong>45</strong>]
[-][<strong>2</strong>][<strong>31</strong>][<strong>52</strong>]
[-][-][-][<strong>3</strong>][-][<strong>234</strong>][-][-]
[-][-][-][-][-][-][-][<strong>5</strong>][-][-][-][-][-][-][-][-] Print the matrix and you're done! :) At a glance, I don't see any problems with the logistics and the code should be pretty simple. But I can't say for sure unless I try it myself.