Add snake struct

This commit is contained in:
d3vyce 2022-07-27 11:22:36 +02:00
parent bcb6661a4c
commit 338f87686c

View File

@ -0,0 +1,28 @@
class List:
def __init__(self, val, next):
self.val = val
self.next = next
def __str__(self):
if self.next == None:
return(f"{self.val} -> None")
else:
return(f"{self.val} -> {str(self.next)}")
def is_empty(L):
return L is None
def List_add(L, value):
if L == None:
return List(value, None)
else:
return List(L.val, List.List_add(L.next, value))
def List_size(L):
i = 0
while L is not None:
i += 1
L = L.next
return i