Skip to content

Commit aef627f

Browse files
author
IanDoarn
committed
Reverted changes
- stack.py, binary_search.py, depth_first_search.py Signed-off-by: IanDoarn <[email protected]>
1 parent a79982f commit aef627f

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

pygorithm/data_structures/stack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def infix_to_postfix(self):
127127
postfix.append(top_operator)
128128
top_operator = self.my_stack.pop()
129129
else:
130-
while not self.my_stack.is_empty() \
131-
and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
130+
while not self.my_stack.is_empty() and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
132131
postfix.append(self.my_stack.pop())
133132
self.my_stack.push(self.expression[i])
134133

pygorithm/searching/binary_search.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ def search(_list, target):
2929
# Last position of the list
3030
right = len(_list) - 1
3131

32-
# you can also write while True condition
33-
while left <= right:
34-
mid = (left + right) // 2
35-
if target == _list[mid]:
36-
return mid
37-
elif target < _list[mid]:
38-
right = mid - 1
39-
else:
40-
left = mid + 1
41-
return False
32+
try:
33+
# you can also write while True condition
34+
while left <= right:
35+
mid = (left + right) // 2
36+
if target == _list[mid]:
37+
return mid
38+
elif target < _list[mid]:
39+
right = mid - 1
40+
else:
41+
left = mid + 1
42+
return False
43+
except TypeError:
44+
return False
4245

4346

4447
# TODO: Are these necessary?

pygorithm/searching/depth_first_search.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import inspect
66

77

8-
def search(graph, start, path=None):
8+
def search(graph, start, path=[]):
99
"""
1010
depth first search algorithm
1111
@@ -18,11 +18,11 @@ def search(graph, start, path=None):
1818
if start not in graph or graph[start] is None or graph[start] == []:
1919
return path
2020

21-
_path = path + [start]
21+
path = path + [start]
2222
for edge in graph[start]:
23-
if edge not in _path:
24-
_path = search(graph, edge, _path)
25-
return _path
23+
if edge not in path:
24+
path = search(graph, edge, path)
25+
return path
2626

2727

2828
# TODO: Are these necessary?

0 commit comments

Comments
 (0)