In this practice, we will be implementing several custom methods for the linked list class.
- You are required to use python.
- For help you can use the lecture slides.
Given the code for the following linked list class...
Complete the printrange method. The method takes two integer numbers x and y as input and print the items from position x to y (Assuming the first item is at position 1 and x>=y).
Example 1:
P = 1->2->3->4->5
P.printrange(3,5) will print 3 4 5
Example 2:
P = None
P.printrange(3,5) will print “No item in range”
Example 3:
P = 1->2->3->4->5
P.printrange(3,10) will print 3 4 5
Complete the alternateListjoin method. Both p and q are LinkedList objects. The method inserts nodes of linked list q at alternate position of the list pointed by self.
Example 1:
P = 1->3->5->7->9 and
q = 2->4->6->8->10
P.alternateListjoin(q) method will result in P = 1->2->3->4->5->6->7->8->9->10 and q = null
Example 2:
P = 1->3->5 and
q = 2->4->6->8->10
P.alternateListjoin(q) method will result in P = 1->2->3->4->5->6 and q = 8->10
Example 3:
P = 1->3->5->7->9 and
q = 2->4->6
P.alternateListjoin(q) method will result in P = 1->2->3->4->5->6->7->9 and q = null
Write a code to test your implementation for various cases.