a) Write a function to get the value of the Nth node in a Linked List. [Note: The first (N=1) item in the list means the
Posted: Mon May 09, 2022 5:53 am
a) Write a function to get the value of the
Nth node in a Linked List. [Note: The first (N=1)
item in the list means the item at index 0.] It takes two
parameters: the list or its head, and N. Return False if the list
has fewer than N elements. The Linked List structure supports the
following function.
def getHead(self):
return self.head # it points to a Node
structure
The Node structure supports the following functions.
def getData(self):
return self.data # it returns the value
stored in the Node
def getNext(self):
return self.next # it points to the next
Node
b) Write a function that counts the number of times a given
integer occurs in a Linked List. Assume similar structures as
defined in (1).
Nth node in a Linked List. [Note: The first (N=1)
item in the list means the item at index 0.] It takes two
parameters: the list or its head, and N. Return False if the list
has fewer than N elements. The Linked List structure supports the
following function.
def getHead(self):
return self.head # it points to a Node
structure
The Node structure supports the following functions.
def getData(self):
return self.data # it returns the value
stored in the Node
def getNext(self):
return self.next # it points to the next
Node
b) Write a function that counts the number of times a given
integer occurs in a Linked List. Assume similar structures as
defined in (1).