update: add traversePostOrder

This commit is contained in:
Sobottasgithub
2026-02-09 09:39:10 +01:00
parent 9b6164665a
commit 1a022f6584
2 changed files with 30 additions and 18 deletions

View File

@@ -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();