-
Notifications
You must be signed in to change notification settings - Fork 0
/
singly_linked_list.py
39 lines (33 loc) · 1017 Bytes
/
singly_linked_list.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
#!/usr/bin/env python3
from nodes import SLLNode
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
self.size = 0
def append(self, data):
node = SLLNode(data)
if self.head is None:
self.head = self.tail = node
else:
self.head.next = node
self.head = node
self.size += 1
def search(self, data):
current = self.head
while current:
if current.data == data
return current
current = current.next
raise Exception('no such data is stored in the list')
def remove(self, data):
current = self.head
previous = current
while self.head == data:
self.head = self.head.next
while current:
if current.data == data
previous.next = current.next
previous = current
current = current.next
print('no such data is stored in the list')