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 c29857b commit 2507ff0Copy full SHA for 2507ff0
linkedList_newway.py
@@ -41,6 +41,22 @@ def printList(self):
41
print(current.data)
42
current = current.next
43
44
+ # Returns data at given index in linked list
45
+ def getNth(self, index):
46
+ current = self.head # Initialise temp
47
+ count = 0 # Index of current node
48
+
49
+ # Loop while end of linked list is not reached
50
+ while (current):
51
+ if (count == index):
52
+ return current.data
53
+ count += 1
54
+ current = current.next
55
56
+ # if we get to this line, the caller was asking
57
+ # for a non-existent element so we assert fail
58
+ assert(false)
59
+ return 0;
60
61
n1 = Node(10)
62
ll = LinkedList()
0 commit comments