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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
64 changes: 56 additions & 8 deletions python/linked_list.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
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, head=None):
self.head = head
self.length = 0

def add(self, data):
# write your code to ADD an element to the Linked List
pass
if not self.head:
new_node = Node(data)
self.head = new_node
else:
previous_node = self.head
while previous_node.next_node:
current_node = previous_node.next_node
previous_node = current_node
new_node = Node(data)
previous_node.next_node = new_node
self.length += 1


def remove(self, data):
# write your code to REMOVE an element from the Linked List
pass
if self.head.data == data:
self.head = self.head.next_node
else:
previous_node = self.head
current_node = self.head.next_node
while current_node.data != data:
previous_node = current_node
current_node = current_node.next_node
previous_node.next_node = current_node.next_node
self.length -= 1


def get(self, element_to_get):
# write you code to GET and return an element from the Linked List
pass
current_node = self.head
for _i in range(0, element_to_get):
current_node = current_node.next_node
return current_node.data


# ----- Node ------
class Node:
# store your DATA and NEXT values here
pass

def __init__(self, data, next_node=None):
self.data = data
self.next_node=next_node


ll = LinkList()
ll.add(1)
ll.add(2)
ll.add(3)

print(ll.head)
print(ll.head.data)
print(ll.head.next_node.data)
print(ll.head.next_node.next_node.data)
print(ll.length)

# ll.remove(3)

print(ll.head.data)
print(ll.head.next_node.data)
print(ll.length)

print(ll.get(0))

19 changes: 14 additions & 5 deletions python/queue.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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.total = 0
self.queue = []

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, data):
def dequeue(self):
# write your code to removes the data to the Queue following FIFO and return the Queue
pass
if not self.queue:
return 'Nothing to dequeue'
self.queue.pop(0)
self.total -= 1
return self.queue

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

def push(self):
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 not self.stack:
return 'Nothing to pop'
self.stack.pop()
self.total -= 1
return self.stack

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