You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Java/Ch 04. Trees and Graphs/Introduction/Traversals.java Please fix the recursive call for the preorder and postorder function.
Here is what is found inside Traversals.java
public static void preOrderTraversal(TreeNode node) {
if (node != null) {
visit(node);
inOrderTraversal(node.left);
inOrderTraversal(node.right);
}
}
public static void postOrderTraversal(TreeNode node) {
if (node != null) {
inOrderTraversal(node.left);
inOrderTraversal(node.right);
visit(node);
}
}
Make it as following
public static void preOrderTraversal(TreeNode node) {
if (node != null) {
visit(node);
preOrderTraversal(node.left);
preOrderTraversal(node.right);
}
}
public static void postOrderTraversal(TreeNode node) {
if (node != null) {
postOrderTraversal(node.left);
postOrderTraversal(node.right);
visit(node);
}
}
The text was updated successfully, but these errors were encountered:
Java/Ch 04. Trees and Graphs/Introduction/Traversals.java Please fix the recursive call for the preorder and postorder function.
Here is what is found inside Traversals.java
}
Make it as following
public static void preOrderTraversal(TreeNode node) {
if (node != null) {
visit(node);
preOrderTraversal(node.left);
preOrderTraversal(node.right);
}
}
}
The text was updated successfully, but these errors were encountered: