Skip to content

Commit c9e3a6a

Browse files
committed
update: reverse order of pushing nodes
1 parent 252e912 commit c9e3a6a

File tree

1 file changed

+3
-3
lines changed
  • src/_DataStructures_/Trees/BinarySearchTree/find-ancestors

1 file changed

+3
-3
lines changed

src/_DataStructures_/Trees/BinarySearchTree/find-ancestors/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ function findAncestors(root, value) {
1111
if (value > root.value) {
1212
// traverse right
1313
const left = findAncestors(root.rightChild, value);
14-
arr = [...arr, ...left];
14+
arr = [...left, ...arr];
1515
}
1616
if (value < root.value) {
1717
// traverse left
1818
const right = findAncestors(root.leftChild, value);
19-
arr = [...arr, ...right];
19+
arr = [...right, ...arr];
2020
}
2121
if (root.value === value) return arr;
22-
arr = [root.value, ...arr];
22+
arr = [...arr, root.value];
2323
return arr;
2424
}
2525

0 commit comments

Comments
 (0)