二进制搜索树在一定数量的节点之后不会插入

时间:2017-05-01 16:30:38

标签: python python-3.x data-structures insert binary-search-tree

我实现了插入插入功能,如下所示。

root = Node(8)
root.insert(3)
root.insert(10)
root.insert(1)
root.insert(6)
root.insert(5) 

我给出了以下输入

Traceback (most recent call last):
  File "C:\Users\\Desktop\BST.py", line 45, in <module>
    root.insert(5)
  File "C:\Users\\Desktop\BST.py", line 15, in insert
    self.left.insert(data)
  File "C:\Users\\Desktop\BST.py", line 20, in insert
    self.data.insert(data)
AttributeError: 'int' object has no attribute 'insert'

但是在root.insert(6)之后会抛出一个错误。

{{1}}

我也试过其他数字,但我仍然得到错误。任何人都可以给我一个理由吗?任何帮助表示赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

//skin is the skin that you use Label myLabel = new Label(text, new LabelStyle(skin.get(LabelStyle.class))); (第20行)替换为self.data.insert(data)