我试图拥有一个二分搜索树,并且该树包含包含人的节点,但是我得到了一个错误,即它没有采用位置参数。
class BST:
def __init__(self):
self.root = None
def setRoot(self, ppl):
self.root = Node(ppl)
def insert(self, ppl):
if (self.root is None):
self.setRoot(ppl) ##If there is no set root, it sets node as root
else:
self.insertNode(self.root, ppl) ##if there is a root, it'll move onto insertNode
def insertNode(self, currentNode, ppl):
if (ppl <= currentNode.ppl):
if (currentNode.leftChild):
self.insertNode(currentNode.leftChild, ppl)
else:
currentNode.leftChild = Node(ppl)
elif (ppl > currentNode.ppl):
if (currentNode.rightChild):
self.insertNode(currentNode.rightChild, ppl)
else:
currentNode.rightChild = Node(ppl)
Class Town:
def add_citizen(self, ppl: Person):
"""Adds a person to the town."""
self.q.inQ(ppl)
Node(ppl)
BST.insert(ppl)
我希望有一个二叉搜索树。
Error:File , line 141, in add_citizen
BST.insert(ppl)
TypeError: insert() missing 1 required positional argument: 'ppl'