Bug in BinarySearchTree.from()
: Removing Elements from Copy Corrupts Original Tree
#6314
Labels
BinarySearchTree.from()
: Removing Elements from Copy Corrupts Original Tree
#6314
Describe the bug
When creating a copy of a
BinarySearchTree
using theBinarySearchTree.from()
method, removing an element from the copied tree inadvertently affects the original tree. Specifically, the original tree either loses elements or its internal structure becomes inconsistent after modifications to the copy.Steps to Reproduce
BinarySearchTree
with the values[3, 10, 13, 4, 6, 7, 1, 14]
.BinarySearchTree.from(original)
to create a copy of the original tree.7
from the copied tree usingcopy.remove(7)
.7
in the original tree usingoriginal.find(7)
.Expected behavior
After removing the value
7
from the copied tree, the original tree should remain unaffected. The value7
should still be present in the original tree, and its size and internal structure should remain consistent.Environment
Test Case
The text was updated successfully, but these errors were encountered: