-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.py
More file actions
46 lines (36 loc) · 711 Bytes
/
linked_list.py
File metadata and controls
46 lines (36 loc) · 711 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
43
44
45
46
# single linked lists
class SinglyNode:
def __init__(self,val,next=None):
self.val=val
self.next=next
def __str__(self):
return str(self.val)
head=SinglyNode(1)
A=SinglyNode(3)
B=SinglyNode(4)
C=SinglyNode(7)
head.next=A
A.next=B
B.next=C
#curr =head
#while curr:
## print(curr)
# curr=curr.next
def display(head):
curr = head
elements= []
while curr :
elements.append(str(curr.val))
curr=curr.next
return"->".join(elements)
d=display(head)
print(d)
def search(head,val):
curr = head
while curr:
if val== curr.val:
return True
curr = curr.next
return False
result=search(head,7)
print(result)