All checks were successful
Deploy to Homelab / deploy (push) Successful in 7s
36 lines
829 B
Python
36 lines
829 B
Python
class Node:
|
|
next_node = None
|
|
|
|
def __init__(self, value):
|
|
self.value = value
|
|
|
|
# Homework:
|
|
# Make a linked list class with the functions:
|
|
# - append(node): add a node to the end of the list
|
|
# - insert(node, index): add a node to the middle of the list
|
|
# - remove(index): remove the first matching node from the list
|
|
|
|
class LinkedList:
|
|
head = None
|
|
tail = None
|
|
|
|
def append(self, thing):
|
|
if self.head==None:
|
|
self.head=Node(value=thing)
|
|
self.tail=self.head
|
|
return
|
|
self.tail.nextNode=Node(value=thing)
|
|
self.tail=self.tail.nextNode
|
|
|
|
|
|
list1=LinkedList()
|
|
list1.append('hi')
|
|
list1.append('hi again')
|
|
list1.append('why am I saying hi so many times?')
|
|
print(list1.head.value)
|
|
print(list1.head.nextNode.value)
|
|
print(list1.head.nextNode.nextNode.value)
|
|
|
|
|
|
|