Question: In python please Queue ADT: class Queue(object): def __init__(self): Purpose creates an empty queue Return an empty queue self.data = list() def is_empty(self):

In python please

In python please Queue ADT: class Queue(object): def __init__(self): """ Purpose creates

an empty queue Return an empty queue """ self.data = list() def

Queue ADT:

class Queue(object): def __init__(self): """ Purpose creates an empty queue Return an empty queue """ self.data = list() def is_empty(self): """ Purpose checks if the given queue has no data in it Return: True if the queue has no data, or false otherwise """ return len(self.data) == 0 def size(self): """ Purpose returns the number of data values in the given queue Return: The number of data values in the queue """ return len(self.data) def enqueue(self, value): """ Purpose adds the given data value to the given queue Pre-conditions: queue: a queue created by create() value: data to be added Post-condition: the value is added to the queue Return: (none) """ self.data.append(value) def dequeue(self): """ Purpose removes and returns a data value from the given queue Pre-conditions: queue: a queue created by create() Post-condition: the first value is removed from the queue Return: the first value in the queue """ return self.data.pop(0) def peek(self): """ Purpose returns the value from the front of given queue without removing it Pre-conditions: queue: a queue created by create() Post-condition: None Return: the value at the front of the queue """ return self.data[0] 

Problem Description In this problem, monsters are arriving to a battlefield one-at-a-time. The input for this problem will consist of of a text file indicating the order in which the monsters arrive. Each line of the file consists of a single monster's name. It might look like this: Gezora Moguera Godzilla Mothra In general, the monster names could be anything, but two names are of special significance: Godzilla and Mothra. All other names are for space monsters. A name could occur more than once, and the names Godzilla and Mothra in particular will very likely occur many times. To simulate the battle, your program should keep track of the order in which the space monsters arrive. Whenever either Godzilla or Mothra arrives, they will defeat whichever space monster is currently first in Line. If Godzilla or Mothra arrive when there are no space monsters waiting, nothing happens for now. Two end results of this battle are possible: The space monsters lose if all of the space monsters are defeated. In this case, your program should print out the names of all of the space monsters that were defeated by each of Godzilla and Mothra. The space monsters win. This happens if there is at least one space monster who is not defeated by Godzilla or Mothra. In this case, the program should print out the name of the space monster who is currently first in line Implementation This is a problem where a Queue data structure can be very useful. A simple implementation of the Queue ADT is provided on the course website. Your program must make effective use of the Queue ADT as part of your approach to solving this problem. Sample Output Some sample input files are provided on the course website. For monsters1.txt, your output might look Like this: Page 4 The space monsters were beaten! Godzilla defeated: Moguera Mothra defeated : Gezora Varan Alternatively, for monsters2.txt, your output might look like this: Oh no! The space monsters won thanks to Mechagodzilla We may test your program win inputs beyond just those given here

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!