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 c3d0387 commit cc6d2b0Copy full SHA for cc6d2b0
length of the list.py
@@ -0,0 +1,35 @@
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 countNode(self):
12
+ temp = self.head
13
+ count = 0
14
+ while temp is not None:
15
+ count = count + 1 # we can also write it like count += 1
16
+ temp = temp.next
17
+ return count
18
19
+ def printList(self):
20
21
22
+ print(temp.data)
23
24
25
26
+l1 = LinkedList()
27
+l1.head = Node(10)
28
+l2 = Node(20)
29
+l3 = Node(30)
30
+l4 = Node(40)
31
+l1.head.next = l2
32
+l2.next = l3
33
+l3.next = l4
34
+l1.printList()
35
+print("the length of the linked list is :", l1.countNode())
0 commit comments