-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathavl.py
More file actions
53 lines (42 loc) · 1.62 KB
/
avl.py
File metadata and controls
53 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# AVL Tree: An AVL tree is a self-balancing tree.
# Implement as many operations as possible with recursion.
# If you can't figure it out recursively, use a loop. (But then refactor
# your implementation into a recursive one!)
# Your implementation should pass the tests in test_avl.py.
# Name:
# Collaborators:
# Time spent:
# Note: BST insert and delete methods have been provided for your convenience. Uncomment and modify
class FixMe:
pass
# def insert(self, node):
# if node.key>self.key:
# if self.right is None:
# self.right=node
# else:
# self.right=self.right.insert(node)
# else:
# if self.left is None:
# self.left=node
# else:
# self.left=self.left.insert(node)
# def delete(self, key):
# if self.key == key:
# if self._has_left_child() and self._has_right_child():
# new_root= self.right._minimum()
# self.right= self.right.delete(new_root.key)
# new_root.right= self.right
# new_root.left= self.left
# return new_root
# if self._has_left_child():
# return self.left
# elif self._has_right_child():
# return self.right
# return None
# else:
# if key <= self.key:
# if self._has_left_child():
# self.left= self.left.delete(key)
# else:
# if self._has_right_child():
# self.right= self.right.delete(key)