Merge pull request #1325 from mariaRoxana94/fix-error

Fixed 8XCorrectness_Bugs + 10XBad_Practice_Bugs + 14XDodgy_Code_Bugs
This commit is contained in:
Stepfen Shawn
2020-05-28 23:04:56 +08:00
committed by GitHub
25 changed files with 293 additions and 238 deletions

View File

@@ -15,8 +15,8 @@ public class LevelOrderTraversal {
// Root of the Binary Tree
Node root;
public LevelOrderTraversal() {
root = null;
public LevelOrderTraversal( Node root) {
this.root = root;
}
/* function to print level order traversal of tree*/

View File

@@ -19,11 +19,9 @@ public class LevelOrderTraversalQueue {
}
}
Node root;
/* Given a binary tree. Print its nodes in level order
using array for implementing queue */
void printLevelOrder() {
void printLevelOrder(Node root) {
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
while (!queue.isEmpty()) {

View File

@@ -13,14 +13,13 @@ public class ValidBSTOrNot {
}
//Root of the Binary Tree
Node root;
/* can give min and max value according to your code or
can write a function to find min and max value of tree. */
/* returns true if given search tree is binary
search tree (efficient version) */
boolean isBST() {
boolean isBST(Node root) {
return isBSTUtil(root, Integer.MIN_VALUE,
Integer.MAX_VALUE);
}