Skip to content

Commit 132528d

Browse files
committed
fix bst insert
1 parent d150991 commit 132528d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

java2/dsa/trees/bst/BstInsert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class BstInsert {
88
public static void insert(BinaryNode parent, BinaryNode node, int value) {
99
if (node == null) {
1010
BinaryNode newNode = new BinaryNode(value);
11-
if (value < parent.value) {
11+
if (value <= parent.value) {
1212
parent.left = newNode;
1313
} else {
1414
parent.right = newNode;
@@ -31,6 +31,7 @@ public static void main(String[] args) {
3131
BinaryNode bst = DataSample.getExampleBinarySearchTree();
3232
BstInsert.add(bst, 17);
3333
BstInsert.add(bst, 18);
34+
BstInsert.add(bst, 18);
3435
BstInsert.add(bst, 100);
3536
BstInsert.add(bst, 28);
3637
}

0 commit comments

Comments
 (0)