-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlinked_list.py
More file actions
31 lines (26 loc) · 850 Bytes
/
linked_list.py
File metadata and controls
31 lines (26 loc) · 850 Bytes
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
from .base_linked_list import BaseLinkedList
from .node import Node
class LinkedList(BaseLinkedList):
def __init__(self):
super(LinkedList, self).__init__()
def add(self, data: Node):
if not isinstance(data, Node):
raise TypeError()
if self.node is None:
self.node: Node = data
else:
current = self.node
while current.next is not None:
current = current.next
current.next = data
self.length += 1
@classmethod
def create(cls, node: Node) -> 'LinkedList':
linked_list = LinkedList()
if node is None:
return linked_list
current = node
while current is not None:
linked_list.add(Node(current.data))
current = current.next
return linked_list