We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc6d2b0 commit 3c00072Copy full SHA for 3c00072
search.py
@@ -0,0 +1,39 @@
1
+class Node:
2
+ def __init__(self, data):
3
+ self.data = data
4
+ self.next = None
5
+
6
7
+class LinkedList:
8
+ def __init__(self):
9
+ self.head = None
10
11
+ def search(self, value):
12
+ temp = self.head
13
+ while temp is not None:
14
+ if temp.data == value:
15
+ return True
16
17
+ temp = temp.next
18
+ return False
19
20
+ def printList(self):
21
22
23
+ print(temp.data)
24
25
26
27
+l1 = LinkedList()
28
+l1.head = Node(10)
29
+l2 = Node(20)
30
+l3 = Node(30)
31
+l4 = Node(40)
32
+l1.head.next = l2
33
+l2.next = l3
34
+l3.next = l4
35
+l1.printList()
36
+if l1.search(20):
37
+ print("YES")
38
+else:
39
+ print("NO")
0 commit comments