We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01257c4 commit b2f5a3aCopy full SHA for b2f5a3a
1 file changed
Length_linkedlist
@@ -0,0 +1,32 @@
1
+class ListNode:
2
+ def __init__(self,data):
3
+ self.data=data
4
+ self.next=None
5
+
6
+def length(head):
7
+ tempNode=head
8
+ count=0
9
+ while(tempNode!=None):
10
+ count=count+1
11
+ tempNode=tempNode.next
12
+ print(count)
13
14
+def length_recur(node):
15
+ if (node == None):
16
+ return 0
17
+ else:
18
+ return 1 + length_recur(node.next)
19
20
21
+head = ListNode('d')
22
+node2 = ListNode('g')
23
+node3 = ListNode('r')
24
+node4 = ListNode('o')
25
26
27
+head.next=node2
28
+node2.next=node3
29
+node3.next=node4
30
+node4.next=None
31
32
+print(length_recur(head))
0 commit comments