Skip to content

Commit 5f264a4

Browse files
committed
Fixed bug with tree creation without root node data
1 parent c542d41 commit 5f264a4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pydatastructs/trees/binary_trees.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,12 @@ def insert(self, key, data=None):
19671967
data: Any
19681968
Optional data to store with the key.
19691969
"""
1970+
# Edge case for root node if not intially inserted
1971+
if self.size == 1 and self.tree[0].key is None:
1972+
self.tree[0] = TreeNode(key, data)
1973+
self.tree[0].is_root = True
1974+
return
1975+
19701976
node = TreeNode(key, data)
19711977
self.tree.append(node)
19721978
self.size += 1

0 commit comments

Comments
 (0)