From 338f87686c8580ddbb75e0447a0306bdbaab9a95 Mon Sep 17 00:00:00 2001 From: Nicolas Sudres Date: Wed, 27 Jul 2022 11:22:36 +0200 Subject: [PATCH] Add snake struct --- Snake/src/snake.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Snake/src/snake.py b/Snake/src/snake.py index e69de29..4ab16d8 100644 --- a/Snake/src/snake.py +++ b/Snake/src/snake.py @@ -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