Question: In python please! # We code the class Container as a doubly linked list this week. # Read Sec 2 of the second lecture notes

In python please!

# We code the class Container as a doubly linked list this week. # Read Sec 2 of the second lecture notes # In today's version, code the private function _locate() # so that it meets the specification described at its top # # SUBMISSION # Just code _locate(self, val). Do not change anything else, especially: # class name = Container, the function name = _locate # File name = EX6_26.py # Upload to Vocareum

class Container: class node: def __init__( self, value, nextNode, prevNode ): self.value = value self.next = nextNode self.prev = prevNode

def __init__( self ): self.top = self.last = None self.size = 0

def __len__( self ): return self.size

def _locate( self, val ): # Remember the list is sorted and doubly linked. # It returns " node, found ", where # node = None and found = False if the Container is empty # If it finds a node whose value = val, then return the node, True # If it finds the node that has the smallest value >val, # then return the node, False # Else if it reaches the last pointer without finding a node with value = val # then return None, False # This is a private function, # so the funciton name should start with _ currentNode=self.top while True: if currentNode is None: return None, False # code the rest of _locate. Make a complete case analysis

#In today's version, you don't need to code the three main functions def find( self, val ): dummy = val

def insert( self, val ): dummy = val

def delete( self, val ): dummy = val

#For code check, create a sample container n1 = Container.node(1, None, None) n2 = Container.node(2, None, None) n3 = Container.node(3, None, None) n4 = Container.node(4, None, None) n1.next = n2 n2.next = n3 n3.next = n4 n2.prev = n1 n3.prev = n2 n4.prev = n3 c = Container() c.top = n1 c.last = n4

#Now test _locate() node, found = c._locate(3) print("The located node has the value", node. value, ". The found flag says ", found)

node, found = c._locate(3.5) print("The located node has the value", node. value, ". The found flag says ", found)

node, found = c._locate(6) print("The located node should be none: ", node, ". The found flag says ", found) ### These should print: # The located node has the value 3 . The found flag says True # The located node has the value 4 . The found flag says False # The located node should be none: None . The found flag says False

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!