I need assistence on this problem that I can seem to figure it out. Any help is
Fantastic news! We've Found the answer you've been seeking!
Question:
The question says:
The file Queue_array.py contains the array implementation of the Queue ADT.
We have to add the contents of this file to our login_data_structures project in Eclipse.
For the Queue_array library we have to complete the implementation of the insert method.
For the Queue_array library we have to complete the implementation of the remove and peek methods.
The Queue_arrary.py:
from copy import deepcopy
class Queue:
def __init__(self):
"""
-------------------------------------------------------
Initializes an empty queue. Data is stored in a Python list.
Use: queue = Queue()
-------------------------------------------------------
Returns:
a new Queue object (Queue)
-------------------------------------------------------
"""
self._values = []
def is_empty(self):
"""
-------------------------------------------------------
Determines if the queue is empty.
Use: b = queue.is_empty()
-------------------------------------------------------
Returns:
True if queue is empty, False otherwise.
-------------------------------------------------------
"""
return len(self._values) == 0
def is_full(self):
"""
-------------------------------------------------------
Determines if the queue is full. (Given the expandable nature
of the Python list _values, the queue is never full.)
Use: b = queue.is_full()
-------------------------------------------------------
Returns:
True if queue is full, False otherwise.
-------------------------------------------------------
"""
return False
def __len__(self):
"""
-------------------------------------------------------
Returns the length of the queue.
Use: n = len(queue)
-------------------------------------------------------
Returns:
the number of values in queue.
-------------------------------------------------------
"""
return len(self._values)
def insert(self, value):
"""
-------------------------------------------------------
Adds a copy of value to the rear of the queue.
Use: queue.insert(value)
-------------------------------------------------------
Parameters:
value - a data element (?)
Returns:
None
-------------------------------------------------------
"""
# your code here
return
def remove(self):
"""
-------------------------------------------------------
Removes and returns value from the queue.
Use: value = queue.remove()
-------------------------------------------------------
Returns:
value - the value at the front of the queue - the value is
removed from queue (?)
-------------------------------------------------------
"""
assert len(self._values) > 0, "Cannot remove from an empty queue"
# your code here
return value
def peek(self):
"""
-------------------------------------------------------
Peeks at the front of queue.
Use: value = queue.peek()
-------------------------------------------------------
Returns:
value - a copy of the value at the front of queue -
the value is not removed from queue (?)
-------------------------------------------------------
"""
assert len(self._values) > 0, "Cannot peek at an empty queue"
# your code here
return value
def __iter__(self):
"""
FOR TESTING ONLY
-------------------------------------------------------
Generates a Python iterator. Iterates through the queue
from front to rear.
Use: for value in queue:
-------------------------------------------------------
Returns:
value - the next value in the queue (?)
-------------------------------------------------------
"""
for value in self._values:
yield value
The things we are being tested on:
Test 'is_empty' with various values: '[]'
Test 'is_empty' with various values: '[99]'
Test 'insert' with various values: '[99]'
Test 'insert' with various values: '[33, 11, 22, 55, 44]'
Test 'remove' with various values: '[99]'
Test 'remove' with various values: '[11, 22, 33, 44]'
Test 'remove' with various values: '[33, 11, 22, 55, 44]'
Test 'peek' with various values: '[99]'
Test 'peek' with various values: '[33, 11, 22, 55, 44]'
Test for assertion fails: 'peek'
Test for assertion fails: 'remove'
Test various methods for proper use of 'deepcopy': 'insert'
Test various methods for proper use of 'deepcopy': 'peek'
Test class for calls to forbidden Python functions: 'remove'
Test class for calls to forbidden Python functions: 'input'
Test class for calls to forbidden Python functions: 'print'
Test all methods for multiple calls to 'return':
We are given a hint that is suppose to be helpful:
Although the Stack ADT is a LIFO (Last In, First Out) data structure, and the Queue ADT is a FIFO data structure, they share many similarities in their implementations. Use the Stack ADT implementations as a guideline for implementing your queues.
Related Book For
Posted Date: