Move print to right place
This commit is contained in:
		
							parent
							
								
									5566f8f3f9
								
							
						
					
					
						commit
						b68ff6c72e
					
				
					 2 changed files with 24 additions and 23 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| package aud.exam.prep.tree; | ||||
| 
 | ||||
| abstract class OrderedBinaryTreeNodeProcessor<V> implements OrderedTreeProcessor<V, BinaryTreeNode<V>> { | ||||
| 
 | ||||
|     @Override | ||||
|     public BinaryTreeNode<V> newEmptyTree() { | ||||
|         return null; | ||||
|  | @ -9,28 +10,6 @@ abstract class OrderedBinaryTreeNodeProcessor<V> implements OrderedTreeProcessor | |||
|     @Override | ||||
|     public Iterable<V> iterate(BinaryTreeNode<V> tree) { | ||||
|         return () -> | ||||
|                 new BinaryTreeIterator<>(tree); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void print(BinaryTreeNode<V> tree) { | ||||
|         printRec(tree, 0); | ||||
|     } | ||||
| 
 | ||||
|     private void printRec(BinaryTreeNode<V> tree, int indent) { | ||||
|         if (tree == null) { | ||||
|             System.out.println("- *"); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         System.out.println("-> " + tree.key); | ||||
| 
 | ||||
|         System.out.print(" |".repeat(indent)); | ||||
|         System.out.print(" L"); | ||||
|         printRec(tree.left, indent + 1); | ||||
| 
 | ||||
|         System.out.print(" |".repeat(indent)); | ||||
|         System.out.print(" L"); | ||||
|         printRec(tree.right, indent + 1); | ||||
|             new BinaryTreeIterator<>(tree); | ||||
|     } | ||||
| } | ||||
|  | @ -331,4 +331,26 @@ public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTre | |||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void print(BinaryTreeNode<V> tree) { | ||||
|         printRec(tree, 0); | ||||
|     } | ||||
| 
 | ||||
|     private void printRec(BinaryTreeNode<V> tree, int indent) { | ||||
|         if (tree == null) { | ||||
|             System.out.println("- *"); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         System.out.println("-> " + tree.key); | ||||
| 
 | ||||
|         System.out.print(" |".repeat(indent)); | ||||
|         System.out.print(" L"); | ||||
|         printRec(tree.left, indent + 1); | ||||
| 
 | ||||
|         System.out.print(" |".repeat(indent)); | ||||
|         System.out.print(" L"); | ||||
|         printRec(tree.right, indent + 1); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue