Question: Python programming problem. Thank you given the following code: class Node: def __init__(self, value): self.value = value self.next = None def getValue(self): return self.value def

Python programming problem. Thank you

Python programming problem. Thank you given the following code: class Node: def__init__(self, value): self.value = value self.next = None def getValue(self): return self.valuedef getNext(self): return self.next def setValue(self,new_value): self.value = new_value def setNext(self,new_next): self.next

given the following code:

class Node: def __init__(self, value): self.value = value self.next = 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 __str__(self): return ("{}".format(self.value))

__repr__ = __str__ class LinkedList: def __init__(self): self.head=None self.tail=None self.count=0

def insert(self, after, item): #write your code here

def pop(self): #write your code here

#Make sure the rest of the methods work correclty after you implement insert and pop def append(self, value): if self.head==None: new_node=Node(value) self.head=new_node self.tail=self.head elif self.tail==self.head: self.tail=Node(value) self.head.setNext(self.tail) else: new_node=Node(value) self.tail.setNext(new_node) self.tail=new_node self.count+=1

def remove(self, value): current=self.head previous=None found=False while not found: if current.getValue()==value: found=True else: previous=current current=current.getNext()

if previous==None: self.head=current.getNext() elif current.getNext()==None: self.tail=previous previous.setNext(None) else: previous.setNext(current.getNext())

self.count-=1

def isEmpty(self): return self.head == None

def size(self): return self.count

def add(self, value): new_node=Node(value) new_node.setNext(self.head) self.head=new_node self.count+=1

if self.size()==1: self.tail=new_node

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

def printList(self): temp=self.head while temp: print(temp.value, end=' ') temp=temp.next

Exercise 1 [10 pts] NOTE: There is no partial credit for this exercise, you must ensure the entire code works properly after the addition of new methods In class, we worked on the implementation of a linked list with the following characteristics LinkedListO creates a new list that is empty. It needs no parameters. We are assuming items in the list are unique add item) adds a new Node with value-item to the beginning of the list. It needs the item and returns nothing remove(item) removes the Node with value-item from the list. It needs the item and modifies the list search(item) searches for the Node with value-item in the list. It needs the item and returns a boolean value 1sEmppC) tests to see whether the list is empty. It needs no parameters and returns a boolean value sizeO returns the number of items in the list. It needs no parameters and returns an integer append(item) adds a new Node with value-item to the end of the list. It needs the item and returns nothing. . Modify the LinkedList class to allow the following linked list operations insert(after,item) adds a new Node with value-item to the list after the Node with value-after. It needs the value of the existing node and the new value to be inserted, returns nothing. [5 pts] popO removes and returns the value of the last Node in the list. It needs no parameters and modifies the list and returns an item. [5pts]

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!