Skip to content

Commit

Permalink
formatted using black and added logo
Browse files Browse the repository at this point in the history
used black and added suggested logo change
  • Loading branch information
MrWeast committed Dec 1, 2023
1 parent 3a5ca42 commit b98c692
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ In order to achieve greater coverage and encourage more people to contribute to
</td>
<td> <!-- Python -->
<a href="./src/python/unordered_linked_list.py">
<img align="center" height="25" src="./logos/github.svg" />
<img align="center" height="25" src="./logos/python.svg" />
</a>
</td>
<td> <!-- Go -->
Expand Down
51 changes: 23 additions & 28 deletions src/python/unordered_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@

class Node:

def __init__(self,value,rptr=None) -> None:
def __init__(self, value, rptr=None) -> None:
self.value = value
self.rptr = rptr

@property
def get_value(self):
return self.value

@property
def next(self):
return self.rptr

@next.setter
def next(self,ptr):
def next(self, ptr):
self.rptr = ptr


class Unordered_Linked_List:
def __init__(self) -> None:
self.first_node = None
def insert(self,value):

def insert(self, value):
# inserts a new node with the given value
if self.first_node is None:
self.first_node = Node(value)
else:
tmp = Node(value)
tmp.next = self.first_node
self.first_node = tmp
def find(self,value):

def find(self, value):
# returns true if the specified value is in your list
ptr = self.first_node
while ptr is not None:
if ptr.value == value:
print(f'{value} is in your list')
print(f"{value} is in your list")
return True
else:
ptr = ptr.next
print(f'{value} is not in your list')

print(f"{value} is not in your list")
return False
def size(self): # returns size of the list

def size(self): # returns size of the list
ptr = self.first_node
i = 0
while ptr is not None:
ptr = ptr.next
i+=1
print(f'Your list is of size {i}')
i += 1
print(f"Your list is of size {i}")
return i
def remove(self,value):

def remove(self, value):
# removes all instances of a given value
ptr = self.first_node
prev = None
Expand All @@ -64,19 +62,20 @@ def remove(self,value):
self.first_node = tmp
else:
prev.next = ptr.next

prev = ptr
ptr = ptr.next

def show(self):
ptr = self.first_node
val = []
while ptr is not None:
val.append(ptr.get_value)
ptr = ptr.next

print(val)


def main():
list = Unordered_Linked_List()

Expand All @@ -102,17 +101,13 @@ def main():
list.insert(3)
list.insert(5)
list.insert(3)

list.show()

list.remove(3)

list.show()




if __name__ == "__main__":
main()


0 comments on commit b98c692

Please sign in to comment.