Question
PYTHON: Implement Functions addFirst, addLast, addBefore, addAfter class Node: def __init__(self, value): self.value = value self.next = None self.prev = None def getValue(self): return self.value
PYTHON: Implement Functions addFirst, addLast, addBefore, addAfter
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started