Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code is in python. Here is the given skelton key: class Deque: A double-ended queue def __init__(self): Initializes an empty Deque

image text in transcribed

This code is in python. Here is the given skelton key:

class Deque: """ A double-ended queue """

def __init__(self): """ Initializes an empty Deque """ pass

def __len__(self): """ Computes the number of elements in the Deque :return: The logical size of the Deque """ return 0

def peek_front(self): """ Looks at, but does not remove, the first element :return: The first element """ raise IndexError

def peek_back(self): """ Looks at, but does not remove, the last element :return: The last element """ raise IndexError

def push_front(self, e): """ Inserts an element at the front of the Deque :param e: An element to insert """ pass

def push_back(self, e): """ Inserts an element at the back of the Deque :param e: An element to insert """ pass

def pop_front(self): """ Removes and returns the first element :return: The (former) first element """ raise IndexError

def pop_back(self): """ Removes and returns the last element :return: The (former) last element """ raise IndexError

def clear(self): """ Removes all elements from the Deque :return: """ pass

def retain_if(self, condition): """ Removes items from the Deque so that only items satisfying the given condition remain :param condition: A boolean function that tests elements """ pass

def __iter__(self): """ Iterates over this Deque from front to back :return: An iterator """ pass

# provided functions

def is_empty(self): """ Checks if the Deque is empty :return: True if the Deque contains no elements, False otherwise """ return len(self) == 0

def __repr__(self): """ A string representation of this Deque :return: A string """ return 'Deque([{0}])'.format(','.join(str(item) for item in self))

1 Assignment Overview For this project you will be implementing a double-ended queue (or deque). Your deque will be used to store and manipulate date from a given text file. In addition to the standard deque methods, you will be implementing three bulk methods for modifying the whole deque 2 Assignment Deliverables You must turn in completed versions of the following files Deque.py Be sure to use the specified file name and to submit your files for grading via D2L Dropbox before the project deadline 3 Assignment Specifications Your task will be to complete the methods listed below peek front peek back push.front push.back * pop.front * pop back clear retain if iter Your implementation of the first seven methods should run in O(1) amortized time. clear and retain if may run in O(n) time. iter can take up to O(n) time total to yield all of the items (each individual item should be produced in amortized constant time). Your deque must use O(n) space The peek and pop methods should raise a IndexError if the deque is empty. No other exceptions should be thrown You should include comments where appropriate. In particular, you should describe the overall method used to implement your deque 1 Assignment Overview For this project you will be implementing a double-ended queue (or deque). Your deque will be used to store and manipulate date from a given text file. In addition to the standard deque methods, you will be implementing three bulk methods for modifying the whole deque 2 Assignment Deliverables You must turn in completed versions of the following files Deque.py Be sure to use the specified file name and to submit your files for grading via D2L Dropbox before the project deadline 3 Assignment Specifications Your task will be to complete the methods listed below peek front peek back push.front push.back * pop.front * pop back clear retain if iter Your implementation of the first seven methods should run in O(1) amortized time. clear and retain if may run in O(n) time. iter can take up to O(n) time total to yield all of the items (each individual item should be produced in amortized constant time). Your deque must use O(n) space The peek and pop methods should raise a IndexError if the deque is empty. No other exceptions should be thrown You should include comments where appropriate. In particular, you should describe the overall method used to implement your deque

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

The Functions of Language Problems with Language

Answered: 1 week ago