diff --git a/data_structures/binary_search_tree.ts b/data_structures/binary_search_tree.ts index 4fa0e2b75475..4ac1c352538a 100644 --- a/data_structures/binary_search_tree.ts +++ b/data_structures/binary_search_tree.ts @@ -281,6 +281,7 @@ export class BinarySearchTree implements Iterable { nodes.push(right); } } + result.#size = collection.#size; } } else { result = (options?.compare diff --git a/data_structures/binary_search_tree_test.ts b/data_structures/binary_search_tree_test.ts index 3d5f80c4e0ec..c587dd26a617 100644 --- a/data_structures/binary_search_tree_test.ts +++ b/data_structures/binary_search_tree_test.ts @@ -392,6 +392,7 @@ Deno.test("BinarySearchTree.from() handles default ascend comparator", () => { let tree: BinarySearchTree = BinarySearchTree.from(originalTree); assertEquals([...originalTree], expected); assertEquals([...tree], expected); + assertEquals(tree.size, originalTree.size); assertEquals([...tree.nlrValues()], [...originalTree.nlrValues()]); assertEquals([...tree.lvlValues()], [...originalTree.lvlValues()]); @@ -443,6 +444,7 @@ Deno.test("BinarySearchTree.from() handles descend comparator", () => { let tree: BinarySearchTree = BinarySearchTree.from(originalTree); assertEquals([...originalTree], expected); assertEquals([...tree], expected); + assertEquals(tree.size, originalTree.size); assertEquals([...tree.nlrValues()], [...originalTree.nlrValues()]); assertEquals([...tree.lvlValues()], [...originalTree.lvlValues()]);