[Home]History of Binary search tree

HomePage | Recent Changes | Preferences

Revision 6 . . December 18, 2001 12:48 am by Taw [removed passing comparision function as argument, that only obscured sample implementation]
Revision 5 . . (edit) October 30, 2001 5:04 am by Kragen [Typographical fix.]
  

Difference (from prior major revision) (no other diffs)

Changed: 6c6
def binary_tree_insert(treenode, value, greaterthan):
def binary_tree_insert(treenode, value):

Changed: 9,10c9,10
if greaterthan(nodevalue, value):
return (binary_tree_insert(left, value, greaterthan), nodevalue, right)
if nodevalue > value:
return (binary_tree_insert(left, value), nodevalue, right)

Changed: 12c12
return (left, nodevalue, binary_tree_insert(right, value, greaterthan))
return (left, nodevalue, binary_tree_insert(right, value))

Changed: 14c14
def build_binary_tree(values, greaterthan=lambda x, y: x > y):
def build_binary_tree(values):

Changed: 17c17
tree = binary_tree_insert(tree, v, greaterthan)
tree = binary_tree_insert(tree, v)

Changed: 20c20
def search_binary_tree(treenode, value, greaterthan=lambda x, y: x > y):
def search_binary_tree(treenode, value):

Changed: 23,26c23,26
if greaterthan(nodevalue, value):
return search_binary_tree(left, value, greaterthan)
elif greaterthan(value, nodevalue):
return search_binary_tree(right, value, greaterthan)
if nodevalue > value:
return search_binary_tree(left, value)
elif value > nodevalue:
return search_binary_tree(right, value)

Changed: 40,41c40
return (traverse_binary_tree(left) + [value] +
traverse_binary_tree(right))
return (traverse_binary_tree(left) + [value] + traverse_binary_tree(right))

Changed: 47,48c46,47
def treesort(array, cmp=lambda x, y: x > y):
array[:] = traverse_binary_tree(build_binary_tree(array, cmp))
def treesort(array):
array[:] = traverse_binary_tree(build_binary_tree(array))

HomePage | Recent Changes | Preferences
Search: