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
41 changes: 36 additions & 5 deletions python/linked_list.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
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 = Node('HEAD')
self.size = 0

def add(self, data):
# write your code to ADD an element to the Linked List
pass
new_node = Node(data)
#find the starting point
current_position = self.head

def remove(self, data):
#find our way to the end
while current_position.next:
previous = current_position
current_position = previous.next

#now at the end lets make sure the previous node knows we are here
current_position.next = new_node
self.size += 1

def remove(self, target_data):
# write your code to REMOVE an element from the Linked List
pass
current_position = self.head
while current_position.data != target_data:
previous = current_position
current_position = previous.next
previous.next = current_position.next
self.size -1

def get(self, element_to_get):
# write you code to GET and return an element from the Linked List
pass
if element_to_get <= self.size:
current_position = self.head
current_element = 0
while current_element < element_to_get:
previous = current_position
current_position = previous.next
current_element +=1
return current_position.data


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


22 changes: 16 additions & 6 deletions python/queue.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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):
# every time we add to queue need to increment a counter
self.queue = []
self.total = 0

def enqueue(self):
def enqueue(self, data):
# write your code to add data to the Queue following FIFO and return the Queue
pass
self.queue.append(data)
self.total +=1
return self.queue

def dequeue(self):
# write your code to removes the data to the Queue following FIFO and return the first item
if self.total > 0:
value = self.queue.pop(0)
self.total -= 1
return value

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

def size(self):
# write your code that returns the size of the Queue
pass
return self.total
21 changes: 16 additions & 5 deletions python/stack.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
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):

def push(self):
self.stack = []
self.total = 0


def push(self, data):
# write your code to add data following LIFO and return the Stack
pass
self.stack.append(data)
self.total += 1
return self.stack

def pop(self, data):
def pop(self):
# write your code to removes the data following LIFO and return the Stack
pass
if self.total > 0:
value = self.stack.pop()
self.total -= 1
return value


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