-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked.py
More file actions
42 lines (34 loc) · 995 Bytes
/
Copy pathlinked.py
File metadata and controls
42 lines (34 loc) · 995 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
32
33
34
35
36
37
38
39
40
41
42
class Node:
def __init__(self, value, _next=None):
self.value = value
self.next = _next
class LinkedList:
def __init__(self, head=None):
self.head = head
def insert(self, value):
node = Node(value)
node.next = self.head
self.head = node
return node.value
def includes(self, value):
current_node = self.head
while current_node is not None:
if current_node.value == value:
return True
current_node = current_node.next
return False
def to_string(self):
current_node = self.head
string = ""
while current_node is not None:
string += f" {current_node.value} ->"
current_node = current_node.next
string += ("Null")
return string
if __name__ == "__main__":
list0 = LinkedList()
list0.insert(34)
list0.insert(35)
list0.insert(36)
list0.to_string()
list0.includes(35)