-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhometask9.py
More file actions
140 lines (105 loc) · 2.5 KB
/
hometask9.py
File metadata and controls
140 lines (105 loc) · 2.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#! usr/bin/env python
from __future__ import division, print_function
import itertools
import random
class Node(object):
def __init__(self, value=None, parent=None, l_child=None, r_child=None):
"""
:param value:
:param parent:
:param l_child:
:param r_child:
:return:
"""
self._value = value
self._parent = parent
self._l_child = l_child if l_child else None
self._r_child = r_child if r_child else None
@property
def value(self):
return self._value
@property
def parent(self):
return self._parent
@property
def l_child(self):
return self._l_child
@property
def r_child(self):
return self._r_child
def __str__(self):
return str((self.value, self.parent, self.l_child, self.r_child))
def __ne__(self, other):
"""
:type other: Node
:return:
"""
return not self == other
def __eq__(self, other):
"""
:type other: Node
:return:
"""
return self.priority == other.priority
def __gt__(self, other):
"""
:type other: Node
:return:
"""
return self.priority > other.priority
def __ge__(self, other):
"""
:type other: Node
:return:
"""
return self.priority >= other.priority
def __lt__(self, other):
"""
:type other: Node
:return:
"""
return self.priority < other.priority
def __le__(self, other):
"""
:type other: Node
:return:
"""
return self.priority <= other.priority
class SearchTree(object):
def __init__(self):
self.
def push(item):
def pop(value, default=None):
def find(value):
def __contains__(self, item):
"""
:param item:
:return:
"""
# def bin_tree_search():
# """
#
# :return:
# """
#
# def bin_search(sequence, target):
# """
# :type sequence: collections.Sequense
# :param sequence:
# :return:
# """
# start = 0
# stop = len(sequence)
# while stop - start >= 1:
# cur_pos = (start + stop)//2
# if sequence[cur_pos] == target:
# return True
# if sequence[cur_pos] > target:
# stop = cur_pos
# else:
# start = cur_pos
# return target in (start, stop)
def main():
pass
if __name__ == "__main__":
main()