Skip to content

Commit

Permalink
Create __init__.py
Browse files Browse the repository at this point in the history
Initialising a LinkedList class, using a Node class to store the item and the next pointer.
  • Loading branch information
theycallmemac authored Oct 14, 2016
1 parent 0dbd2df commit 4a8fa8b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions data_structures/LinkedList/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Node:
def __init__(self, item, next):
self.item = item
self.next = next

class LinkedList:
def __init__(self):
self.head = None

def add(self, item):
self.head = Node(item, self.head)

def remove(self):
if self.is_empty():
return None
else:
item = self.head.item
self.head = self.head.next
return item

def is_empty(self):
return self.head == None

0 comments on commit 4a8fa8b

Please sign in to comment.