本文整理汇总了Python中Node.Node.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Node.remove方法的具体用法?Python Node.remove怎么用?Python Node.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BinarySearchTree
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import remove [as 别名]
class BinarySearchTree(object):
def __init__(self):
self.rootNode = None
def insert(self, data):
if not self.rootNode:
# first element
self.rootNode = Node(data)
else:
self.rootNode.insert(data)
def remove(self, dataToRemove):
if self.rootNode:
if self.rootNode == dataToRemove:
tempNode = Node(None)
tempNode.leftChild = self.rootNode
self.rootNode.remove(dataToRemove, tempNode)
else:
self.rootNode.remove(dataToRemove, None)
def getMax(self):
if self.rootNode:
return self.rootNode.getMax()
def getMin(self):
if self.rootNode:
return self.rootNode.minValue()
def traverseInOrder(self):
if self.rootNode:
self.rootNode.traverseInOrder()
示例2: BinarySearchTree
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import remove [as 别名]
class BinarySearchTree(object):
def __init__(self):
self.root_node = None
def insert(self, data):
if self.root_node is None:
self.root_node = Node(data)
else:
self.root_node.insert(data)
def remove(self, data):
if self.root_node:
if self.root_node.data == data:
temp_node = Node(None)
temp_node.left_child = self.root_node
self.root_node.remove(data, temp_node)
self.root_node = temp_node.left_child
else:
self.root_node.remove(data, None)
def getMax(self):
if self.root_node:
return self.root_node.getMax()
def getMin(self):
if self.root_node:
return self.root_node.getMin()
def inOrderTraversal(self):
if self.root_node:
return self.root_node.inOrderTraversal()
def inOrderTraversalWithStack(self):
stack = []
if self.root_node:
current = self.root_node
done = False
while not done:
if current is not None:
stack.append(current)
current = current.left_child
else:
if len(stack) != 0:
temp = stack.pop()
print temp.data
current = temp.right_child
else:
done = True
示例3: add
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import remove [as 别名]
def add(self, key, data):
new_node = Node(key, data)
curr = self.__head
prev = None
stop = False
while curr != None and not stop:
if key < curr.get_key():
stop = True
elif key == curr.get_key():
curr.set_data(data)
stop = True
else:
prev = curr
curr = curr.get_next()
new_node.set_next(curr)
if prev == None:
self.__head = new_node
elif prev == new_node:
new_node.remove(key)
else:
prev.set_next(new_node)
self.__count += 1
示例4: BinarySearch
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import remove [as 别名]
class BinarySearch(object):
def __init__(self):
self.rootNode = None;
def insert(self, data):
if not self.rootNode:
self.rootNode = Node(data)
else:
self.rootNode.insert(data)
def remove(self, dataToRemove):
if self.rootNode:
if self.rootNode.data == dataToRemove:
tempNode = Node(Noneo)
tempNode.leftChild = self.rootNode
self.rootNode.remove(dataToRemove, tempNode)
self.rootNode = tempNode.leftChild
else:
self.rootNode.remove(dataToRemove, None)
def getMax(self):
maxNode = self.rootNode
while maxNode.rightChild:
maxNode = maxNode.rightchild
return maxNode.data
def getMin(self):
minNode = self.rootNode
while minNode.leftChild:
minNode =minNode.leftChild
return minNode.data
def traverseInOrder(self):
if self.rootNode:
self.rootNode.traverseInOrder()