Skip to content
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
53 changes: 44 additions & 9 deletions python/linked_list.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
class LinkList:
# write your __init__ method here that should store a 'head' value which the first Node in the LinkedList and a 'length' value which is the total number of Nodes in the LinkedList

def __init__(self):
self.head = None

def __str__(self):
return_list = []
current = self.head
while current:
return_list.append(current.data)
current = current.next
return ', '.join(str(data) for data in return_list)

def add(self, data):
# write your code to ADD an element to the Linked List
pass
insert = Node(data)
if self.head:
current = self.head
while current.next:
current = current.next
current.next = insert
else:
self.head = insert

def remove(self, data):
# write your code to REMOVE an element from the Linked List
pass
previous = None
if self.head.data == data:
self.head.next.data = self.head.data
self.head = self.head.next
current = self.head
while True:
if current.data == data:
previous.next = current.next
break
else:
previous = current
current = current.next


def get(self, element_to_get):
# write you code to GET and return an element from the Linked List
pass
current = self.head
if current.data == element_to_get:
return current
while True:
if current.data == element_to_get:
return current
else:
current = current.next

# ----- Node ------
class Node:
# store your DATA and NEXT values here
pass
def __init__(self, data=None, next=None):
self.data = data
self.next = next

23 changes: 13 additions & 10 deletions python/queue.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
class Queue:
# write your __init__ method here that should store a 'total' value which is the total number of elements in the Queue and a 'queue' value which is an array of stored values in the Queue
def __init__(self):
self.queue = []
self.total = len(self.queue)

def enqueue(self, value):
self.queue.insert(0, value)
self.total = len(self.queue)

def enqueue(self):
# write your code to add data to the Queue following FIFO and return the Queue
pass

def dequeue(self, data):
# write your code to removes the data to the Queue following FIFO and return the Queue
pass
def dequeue(self):
self.queue.pop(-1)

def size(self):
# write your code that returns the size of the Queue
pass
return self.total



23 changes: 13 additions & 10 deletions python/stack.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
class Stack:
# write your __init__ method here that should store a 'total' value which is the total number of elements in the Stack and a 'stack' value which is an array of stored values in the Stack
def __init__(self):
self.stack = []
self.total = len(self.stack)

def push(self, data):
self.stack.append(data)

def push(self):
# write your code to add data following LIFO and return the Stack
pass

def pop(self, data):
# write your code to removes the data following LIFO and return the Stack
pass
def pop(self):
self.stack.pop()

def size(self):
# write your code that returns the size of the Stack
pass
return self.total




37 changes: 37 additions & 0 deletions runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from python.linked_list import LinkList
from python.queue import Queue
from python.stack import Stack

linked_list = LinkList()

linked_list.add(6)
linked_list.add(9)
linked_list.add(11)
linked_list.add(4)
linked_list.add(7)

print(linked_list)

linked_list.get(9)
linked_list.remove(4)
print(linked_list)

queue = Queue()

queue.enqueue(0)
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
print(queue.queue)
# should be 0
queue.dequeue()
print(queue.queue)

stack = Stack()
stack.push(0)
stack.push(1)
stack.push(2)
stack.push(3)
print(stack.stack)
stack.pop()
print(stack.stack)