Question: Python programming question. Given the following code: here is the code from the screenshot above, if it makes it easier to copy. class Node: def

Python programming question.

Python programming question. Given the following code: here is the code fromthe screenshot above, if it makes it easier to copy. class Node:

Given the following code:

def __init__(self, value): self.value = value self.next = None self.prev = Nonedef getValue(self): return self.value def getNext(self): return self.next def setValue(self,new_value): self.value =

new_value def setNext(self,new_next): self.next = new_next def getPrevious(self): return self.prev def setPrevious(self,new_prev):here is the code from the screenshot above, if it makes it easier to copy.

class Node: def __init__(self, value): self.value = value self.next = None self.prev = None

def getValue(self): return self.value

def getNext(self): return self.next

def setValue(self,new_value): self.value = new_value

def setNext(self,new_next): self.next = new_next

def getPrevious(self): return self.prev

def setPrevious(self,new_prev): self.prev = new_prev

def __str__(self): return ("{}".format(self.value))

__repr__ = __str__

class DoublyLinkedList: # Do NOT modify the constructor def __init__(self): self.head = None def addFirst(self, value): # write your code here def addLast(self, value): # write your code here def addBefore(self, pnode_value, value): # write your code here def addAfter(self, pnode_value, value): # write your code here

def printDLL(self): temp=self.head print(" Traversal Head to Tail") while temp: print(temp.getValue(), end=' ') last = temp temp=temp.getNext() print(" Traversal Tail to Head") while(last is not None): print(last.getValue(), end=' ') last = last.prev

def getNode(self,value): current=self.head found=False while current!=None and not found: if current.getValue()==value: found=True return current else: current=current.getNext() return

Instructions: In class, we discussed the Doubly Linked List Abstract Data Type (section 1.1.4 of your Lecture Notes). A Doubly Linked List contains an extra pointer (known as previous pointer) allowing the traversal of the list in both forward and backward direction. When implementing the LinkedList data structure, we observed the importance of updating the pointers in order to get access to the entire list. Implement the data structure DoublyLinkedList with the following characteristics: . DoublyLinkedList) creates a new doubly linked list that is empty. It needs no parameters e addFirt(item) adds a new Node with value-item at the beginning of the list. It needs the addLast(item) adds a new Node with value-item at the end of the list. It needs the item and and returns nothing. Assume the items in the list are unique tem and returns nothing. 20 pts returns nothing. [20 pts] * addBefore(pnode value, item) adds a new Node with value-item before the Node with value=pnode value. It needs the value of the reference Node and the item to be added returns nothing. You can assume the reference node is in the list. [30 pts] e addAfter(pnode value, item) adds a new Node with value-item after the Node with value=pnode-value. It needs the value of the reference Node and the item to be added returns nothing. You can assume the reference node is in the list. [30 pts] NOTE: There is no partial credit for methods that do not workproperly. Code will be tested calling all methods and comparing the final list EXAMPLE >>> dll-DoublyLinkedList () >>>dl1.addFirst (5) >>>d11.addFirst(9) >>>d11.addFirst (4) >>>d11.addFirst (3) >>>dll.head >>>d11.addLast (8) >>> d11.addLast (12) Instructions: In class, we discussed the Doubly Linked List Abstract Data Type (section 1.1.4 of your Lecture Notes). A Doubly Linked List contains an extra pointer (known as previous pointer) allowing the traversal of the list in both forward and backward direction. When implementing the LinkedList data structure, we observed the importance of updating the pointers in order to get access to the entire list. Implement the data structure DoublyLinkedList with the following characteristics: . DoublyLinkedList) creates a new doubly linked list that is empty. It needs no parameters e addFirt(item) adds a new Node with value-item at the beginning of the list. It needs the addLast(item) adds a new Node with value-item at the end of the list. It needs the item and and returns nothing. Assume the items in the list are unique tem and returns nothing. 20 pts returns nothing. [20 pts] * addBefore(pnode value, item) adds a new Node with value-item before the Node with value=pnode value. It needs the value of the reference Node and the item to be added returns nothing. You can assume the reference node is in the list. [30 pts] e addAfter(pnode value, item) adds a new Node with value-item after the Node with value=pnode-value. It needs the value of the reference Node and the item to be added returns nothing. You can assume the reference node is in the list. [30 pts] NOTE: There is no partial credit for methods that do not workproperly. Code will be tested calling all methods and comparing the final list EXAMPLE >>> dll-DoublyLinkedList () >>>dl1.addFirst (5) >>>d11.addFirst(9) >>>d11.addFirst (4) >>>d11.addFirst (3) >>>dll.head >>>d11.addLast (8) >>> d11.addLast (12)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!