Skip to content

Travis CI: Upgrade to Python 3.8 #1373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
python: 3.7
python: 3.8
cache: pip
before_install: pip install --upgrade pip setuptools
install: pip install -r requirements.txt
Expand Down
49 changes: 27 additions & 22 deletions data_structures/linked_list/deque_doubly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,36 @@
4. remove from the end -> O(1)
"""


class _DoublyLinkedBase:
""" A Private class (to be inherited) """

class _Node:
__slots__ = '_prev', '_data', '_next'
__slots__ = "_prev", "_data", "_next"

def __init__(self, link_p, element, link_n):
self._prev = link_p
self._data = element
self._next = link_n

def has_next_and_prev(self):
return " Prev -> {0}, Next -> {1}".format(self._prev != None, self._next != None)

return " Prev -> {0}, Next -> {1}".format(
self._prev != None, self._next != None
)

def __init__(self):
self._header = self._Node(None, None, None)
self._trailer = self._Node(None, None, None)
self._header._next = self._trailer
self._trailer._prev = self._header
self._size = 0

def __len__(self):
return self._size

def is_empty(self):
return self.__len__() == 0

def _insert(self, predecessor, e, successor):
# Create new_node by setting it's prev.link -> header
# setting it's next.link -> trailer
Expand All @@ -40,11 +45,11 @@ def _insert(self, predecessor, e, successor):
successor._prev = new_node
self._size += 1
return self

def _delete(self, node):
predecessor = node._prev
successor = node._next

predecessor._next = successor
successor._prev = predecessor
self._size -= 1
Expand All @@ -53,20 +58,20 @@ def _delete(self, node):
del node
return temp


class LinkedDeque(_DoublyLinkedBase):

def first(self):
""" return first element
>>> d = LinkedDeque()
>>> d.add_first('A').first()
'A'
>>> d.add_first('B').first()
'B'
"""
"""
if self.is_empty():
raise Exception('List is empty')
raise Exception("List is empty")
return self._header._next._data

def last(self):
""" return last element
>>> d = LinkedDeque()
Expand All @@ -76,27 +81,27 @@ def last(self):
'B'
"""
if self.is_empty():
raise Exception('List is empty')
raise Exception("List is empty")
return self._trailer._prev._data

### DEque Insert Operations (At the front, At the end) ###

def add_first(self, element):
""" insertion in the front
>>> LinkedDeque().add_first('AV').first()
'AV'
"""
return self._insert(self._header, element, self._header._next)

def add_last(self, element):
""" insertion in the end
>>> LinkedDeque().add_last('B').last()
'B'
"""
return self._insert(self._trailer._prev, element, self._trailer)

### DEqueu Remove Operations (At the front, At the end) ###

def remove_first(self):
""" removal from the front
>>> d = LinkedDeque()
Expand All @@ -114,9 +119,9 @@ def remove_first(self):
True
"""
if self.is_empty():
raise IndexError('remove_first from empty list')
raise IndexError("remove_first from empty list")
return self._delete(self._header._next)

def remove_last(self):
""" removal in the end
>>> d = LinkedDeque()
Expand All @@ -134,5 +139,5 @@ def remove_last(self):
True
"""
if self.is_empty():
raise IndexError('remove_first from empty list')
raise IndexError("remove_first from empty list")
return self._delete(self._trailer._prev)
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fake_useragent
flake8
matplotlib
mypy
numpy>=1.17.4
numpy>=1.18.1
opencv-python
pandas
pillow
Expand All @@ -14,4 +14,4 @@ requests
scikit-fuzzy
sklearn
sympy
tensorflow
tensorflow==2.1.0rc2
23 changes: 12 additions & 11 deletions sorts/recursive_bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ def bubble_sort(list1):

"""

for i, num in enumerate(list1):
try:
if list1[i+1] < num:
list1[i] = list1[i+1]
list1[i+1] = num
bubble_sort(list1)
except IndexError:
for i, num in enumerate(list1):
try:
if list1[i + 1] < num:
list1[i] = list1[i + 1]
list1[i + 1] = num
bubble_sort(list1)
except IndexError:
pass
return list1
return list1

if __name__ == "__main__":
list1 = [33,99,22,11,66]
bubble_sort(list1)

if __name__ == "__main__":
list1 = [33, 99, 22, 11, 66]
bubble_sort(list1)
print(list1)