update: add traversePostOrder
This commit is contained in:
@@ -7,6 +7,10 @@ public class BinaryTree {
|
||||
insert(content);
|
||||
}
|
||||
|
||||
public Node getRoot() {
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
public boolean search(int value) {
|
||||
if (rootNode == null) {
|
||||
return false;
|
||||
@@ -120,6 +124,14 @@ public class BinaryTree {
|
||||
}
|
||||
}
|
||||
|
||||
public void traversePostOrder(Node node) {
|
||||
if (node != null) {
|
||||
traversePostOrder(node.getLeftNode());
|
||||
traversePostOrder(node.getRightNode());
|
||||
System.out.print(" " + node.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
// Print functions from https://www.baeldung.com/java-print-binary-tree-diagram
|
||||
// public void print() {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user