MCPcopy Index your code
hub / github.com/ndleah/python-mini-project / restructdata

Method restructdata

Binary_Search_Tree/bst.py:31–53  ·  view source on GitHub ↗
(self,root)

Source from the content-addressed store, hash-verified

29 return self.addHelper(root,data)
30
31 def restructdata(self,root):
32 # base case: we reach a leaf
33 if root == None or (root.left == None and root.right == None):
34 root = None
35 return "restructure finished"
36
37 # need dummy nodes to compare target value to children value
38 v1 = float('-inf')
39 v2 = float('inf')
40 if root.left != None:
41 v1 = root.left.val
42 if root.right != None:
43 v2 = root.right.val
44
45 temp = root.val
46 if v1 > v2 or v2 == float('inf'):
47 root.val = root.left.val
48 root.left.val = temp
49 return self.restructdata(root.left)
50 else:
51 root.val = root.right.val
52 root.right.val = temp
53 return self.restructdata(root.right)
54
55
56 def removeHelper(self,root,data):

Callers 1

removeHelperMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected