Skip to content
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

simple-linked-list #25

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest --continue-on-collection-errors
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
git diff origin/main HEAD --name-only -- practice | xargs dirname | sort | uniq | xargs pytest
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
56 changes: 42 additions & 14 deletions practice/simple-linked-list/simple_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,61 @@
class Node:
def __init__(self, value):
pass
def __init__(self, value, next_node=None):
self._value = value
self._next_node = next_node

def value(self):
pass
return self._value

def next(self):
pass


return self._next_node

class LinkedList:
def __init__(self, values=[]):
pass
self._head = None
self._length = 0
# Initialize in normal order
for value in values:
self.push(value)

def __len__(self):
pass
count = 0
node = self._head
while node:
count += 1
node = node.next()
return count

def head(self):
pass
if not self._head:
raise EmptyListException("The list is empty.")
return self._head

def push(self, value):
pass
new_node = Node(value, self._head)
self._head = new_node
self._length += 1

def pop(self):
pass
if self._length == 0:
raise EmptyListException("The list is empty.")
value = self._head.value()
self._head = self._head.next()
self._length -= 1
return value

def reversed(self):
pass


return LinkedList(list(self))

def __iter__(self):
node = self._head
while node:
yield node.value()
node = node.next()

class EmptyListException(Exception):
def __init__(self, message):
self.message = message
pass



Loading