-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestLinkedList.py
executable file
·48 lines (33 loc) · 1017 Bytes
/
TestLinkedList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Cell = Node, SnakeLinkedList = Linked-list_print
#[] -> [] -> [] -> None
#Each '->' is point to another Cell
#
class Cell:
def __init__(self, cord=None):
self.cord = cord
self.next_cell = None
class SnakeLinkedList:
def __init__(self):
self.head_cell = None
def list_print(self):
print_val = self.head_cell
while print_val is not None:
print(print_val.cord)
print_val = print_val.next_cell
def AtEnd(self, new_cell):
NewCell = Cell(new_cell)
if self.head_cell is None:
self.head_cell = NewCell
return
last_cell = self.head_cell
while(last_cell.next_cell):
last_cell = last_cell.next_cell
last_cell.next_cell= NewCell
Snake = SnakeLinkedList()
Snake.head_cell = Cell([120,200])
Snake2 = Cell([130,200])
Snake3 = Cell([140,200])
Snake.head_cell.next_cell = Snake2
Snake2.next_cell = Snake3
Snake.AtEnd([150,200])
Snake.list_print()