-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.py
More file actions
34 lines (29 loc) · 912 Bytes
/
Search.py
File metadata and controls
34 lines (29 loc) · 912 Bytes
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
class SequentialStringList():
def __init__(self) -> None:
self.list: list = []
def add(self, string: str) -> list:
self.list.append(string)
return self.list
def find(self, string: str):
for i in range(len(self.list)):
if self.list[i] == string:
return self.list[i]
return None
class BinaryStringList():
def __init__(self) -> None:
self.list: list = []
def add(self, string: str) -> list:
self.list.append(string)
return self.list
def find(self, string: str):
low: int = 0;
high: int = len(self.list)-1
while low < high:
mid = (low + high)//2
if self.list[mid] == string:
return string
if string > self.list[mid]:
low = mid + 1
else:
high = mid - 1
return None