Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

=+8. Why is productivity important?

Answered: 1 week ago

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago