Skip to content

Commit 1f2b1a8

Browse files
cclausspoyea
authored andcommitted
Typos in comments in hill_climbing.py (TheAlgorithms#1667)
* Typos in comments in hill_climbing.py * fixup! Format Python code with psf/black push
1 parent 36d229f commit 1f2b1a8

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

data_structures/linked_list/deque_doubly.py

+27-22
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,36 @@
77
4. remove from the end -> O(1)
88
"""
99

10+
1011
class _DoublyLinkedBase:
1112
""" A Private class (to be inherited) """
13+
1214
class _Node:
13-
__slots__ = '_prev', '_data', '_next'
15+
__slots__ = "_prev", "_data", "_next"
16+
1417
def __init__(self, link_p, element, link_n):
1518
self._prev = link_p
1619
self._data = element
1720
self._next = link_n
18-
21+
1922
def has_next_and_prev(self):
20-
return " Prev -> {0}, Next -> {1}".format(self._prev != None, self._next != None)
21-
23+
return " Prev -> {0}, Next -> {1}".format(
24+
self._prev != None, self._next != None
25+
)
26+
2227
def __init__(self):
2328
self._header = self._Node(None, None, None)
2429
self._trailer = self._Node(None, None, None)
2530
self._header._next = self._trailer
2631
self._trailer._prev = self._header
2732
self._size = 0
28-
33+
2934
def __len__(self):
3035
return self._size
31-
36+
3237
def is_empty(self):
3338
return self.__len__() == 0
34-
39+
3540
def _insert(self, predecessor, e, successor):
3641
# Create new_node by setting it's prev.link -> header
3742
# setting it's next.link -> trailer
@@ -40,11 +45,11 @@ def _insert(self, predecessor, e, successor):
4045
successor._prev = new_node
4146
self._size += 1
4247
return self
43-
48+
4449
def _delete(self, node):
4550
predecessor = node._prev
4651
successor = node._next
47-
52+
4853
predecessor._next = successor
4954
successor._prev = predecessor
5055
self._size -= 1
@@ -53,20 +58,20 @@ def _delete(self, node):
5358
del node
5459
return temp
5560

61+
5662
class LinkedDeque(_DoublyLinkedBase):
57-
5863
def first(self):
5964
""" return first element
6065
>>> d = LinkedDeque()
6166
>>> d.add_first('A').first()
6267
'A'
6368
>>> d.add_first('B').first()
6469
'B'
65-
"""
70+
"""
6671
if self.is_empty():
67-
raise Exception('List is empty')
72+
raise Exception("List is empty")
6873
return self._header._next._data
69-
74+
7075
def last(self):
7176
""" return last element
7277
>>> d = LinkedDeque()
@@ -76,27 +81,27 @@ def last(self):
7681
'B'
7782
"""
7883
if self.is_empty():
79-
raise Exception('List is empty')
84+
raise Exception("List is empty")
8085
return self._trailer._prev._data
81-
86+
8287
### DEque Insert Operations (At the front, At the end) ###
83-
88+
8489
def add_first(self, element):
8590
""" insertion in the front
8691
>>> LinkedDeque().add_first('AV').first()
8792
'AV'
8893
"""
8994
return self._insert(self._header, element, self._header._next)
90-
95+
9196
def add_last(self, element):
9297
""" insertion in the end
9398
>>> LinkedDeque().add_last('B').last()
9499
'B'
95100
"""
96101
return self._insert(self._trailer._prev, element, self._trailer)
97-
102+
98103
### DEqueu Remove Operations (At the front, At the end) ###
99-
104+
100105
def remove_first(self):
101106
""" removal from the front
102107
>>> d = LinkedDeque()
@@ -114,9 +119,9 @@ def remove_first(self):
114119
True
115120
"""
116121
if self.is_empty():
117-
raise IndexError('remove_first from empty list')
122+
raise IndexError("remove_first from empty list")
118123
return self._delete(self._header._next)
119-
124+
120125
def remove_last(self):
121126
""" removal in the end
122127
>>> d = LinkedDeque()
@@ -134,5 +139,5 @@ def remove_last(self):
134139
True
135140
"""
136141
if self.is_empty():
137-
raise IndexError('remove_first from empty list')
142+
raise IndexError("remove_first from empty list")
138143
return self._delete(self._trailer._prev)

searches/hill_climbing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, x: int, y: int, step_size: int, function_to_optimize):
2323

2424
def score(self) -> int:
2525
"""
26-
Returns the output for the function called with current x and y coordinates.
26+
Returns the output of the function called with current x and y coordinates.
2727
>>> def test_function(x, y):
2828
... return x + y
2929
>>> SearchProblem(0, 0, 1, test_function).score() # 0 + 0 = 0
@@ -91,7 +91,7 @@ def hill_climbing(
9191
have any neighbors which can improve the solution.
9292
Args:
9393
search_prob: The search state at the start.
94-
find_max: If True, the algorithm should find the minimum else the minimum.
94+
find_max: If True, the algorithm should find the maximum else the minimum.
9595
max_x, min_x, max_y, min_y: the maximum and minimum bounds of x and y.
9696
visualization: If True, a matplotlib graph is displayed.
9797
max_iter: number of times to run the iteration.

sorts/recursive_bubble_sort.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ def bubble_sort(list1):
2424
2525
"""
2626

27-
for i, num in enumerate(list1):
28-
try:
29-
if list1[i+1] < num:
30-
list1[i] = list1[i+1]
31-
list1[i+1] = num
32-
bubble_sort(list1)
33-
except IndexError:
27+
for i, num in enumerate(list1):
28+
try:
29+
if list1[i + 1] < num:
30+
list1[i] = list1[i + 1]
31+
list1[i + 1] = num
32+
bubble_sort(list1)
33+
except IndexError:
3434
pass
35-
return list1
35+
return list1
3636

37-
if __name__ == "__main__":
38-
list1 = [33,99,22,11,66]
39-
bubble_sort(list1)
37+
38+
if __name__ == "__main__":
39+
list1 = [33, 99, 22, 11, 66]
40+
bubble_sort(list1)
4041
print(list1)

0 commit comments

Comments
 (0)