2. Create a new Deque class, called Deque2, and modify this class as follows. (You may start by copying the Deque.py file from the pythonds folder.) a. Use a dictionary instead of a list to store the items in the double ended queue. That is, self.items should be initialized to an empty dictionary. i. You will need to determine how you will know the key value for the front and rear of the double ended queue. Hint: you will likely need a few instance variables to keep track of this information. b. Modify each method so that it will work for the self.items dictionary. Have the removeFront and removeRear methods return None when self.items is empty. С. 3. In your deque2.py source code file, add test code to test your Deque2 class. Be sure you are testing each method. b. Be sure you are testing use of a dictionary under the following conditions. i. Does each method work when the dictionary is empty? ii. Does each method work when the dictionary contains exactly one item? iii. Does each method work when the dictionary contains many items? а.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I am unable to make the Deque work with a dictionary. Im new to python, so if someone can assist me with basic python code, that would be great:).

class Deque:
def _init_(self):
self.items = []
def isEmpty(self):
return self.items == []
def addFront (self, item):
self.items.append (item)
def addRear(self, item):
self.items.insert(0,item)
def removeFront (self):
return self.items.pop()
def removeRear(self):
return self.items.pop(0)
def size(self):
return len(self.items)
Transcribed Image Text:class Deque: def _init_(self): self.items = [] def isEmpty(self): return self.items == [] def addFront (self, item): self.items.append (item) def addRear(self, item): self.items.insert(0,item) def removeFront (self): return self.items.pop() def removeRear(self): return self.items.pop(0) def size(self): return len(self.items)
2. Create a new Deque class, called Deque2, and modify this class as follows. (You may start by copying
the Deque.py file from the pythonds folder.)
Use a dictionary instead of a list to store the items in the double ended queue. That is, self.items
should be initialized to an empty dictionary.
i. You will need to determine how you willI know the key value for the front and rear of the
double ended queue. Hint: you will likely need a few instance variables to keep track of this
а.
information.
b. Modify each method so that it will work for the self.items dictionary.
Have the removeFront and removeRear methods return None when self.items is empty.
С.
3. In your deque2.py source code file, add test code to test your Deque2 class.
Be sure you are testing each method.
b. Be sure you are testing use of a dictionary under the following conditions.
i. Does each method work when the dictionary is empty?
ii. Does each method work when the dictionary contains exactly one item?
iii. Does each method work when the dictionary contains many items?
а.
Transcribed Image Text:2. Create a new Deque class, called Deque2, and modify this class as follows. (You may start by copying the Deque.py file from the pythonds folder.) Use a dictionary instead of a list to store the items in the double ended queue. That is, self.items should be initialized to an empty dictionary. i. You will need to determine how you willI know the key value for the front and rear of the double ended queue. Hint: you will likely need a few instance variables to keep track of this а. information. b. Modify each method so that it will work for the self.items dictionary. Have the removeFront and removeRear methods return None when self.items is empty. С. 3. In your deque2.py source code file, add test code to test your Deque2 class. Be sure you are testing each method. b. Be sure you are testing use of a dictionary under the following conditions. i. Does each method work when the dictionary is empty? ii. Does each method work when the dictionary contains exactly one item? iii. Does each method work when the dictionary contains many items? а.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY