Question: what needs to be done for python remove method for doubly linked list def remove ( self , index ) : # remove node at
what needs to be done for python remove method for doubly linked list
def removeself index: # remove node at specified index
s self.size # get size
if s index or index : # check if the index position is valid
raise IndexErrorIndex out of range" # error Message
currentNode self.first # start from first node
if index : # if removing first node,
self.first self.first.next # set the first node to be nd node
self.first.previous None #The new first node has no previous node, so its previous is None
else:
for i in range index: # go to node just before node being removed
currentNode currentNode.next # move to the next node
if currentNodenext is not None: # if there is a node to remove
currentNode.next currentNode.next.next # set the current nodes pointer to skip the node being removed
else:
currentNode.next None # if its the last node, set the pointer to none
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
