Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will implement a double-ended queue (deque) using a doubly-linked list. You may use the code from hw4-skeleton.py on Piazza as a
In this assignment, you will implement a double-ended queue (deque) using a doubly-linked list. You may use the code from "hw4-skeleton.py" on Piazza as a starting point. The "hw4-skeleton.py" module defines a Node class and a Deque class. The Node class is complete and ready to use. Several methods for Deque are already implemented for you, but you will need to implement the remaining methods. (The pre-implemented methods may not work properly until you provide working implementations for the missing methods.) Note that the __iter__() and __reversed__() methods are implemented assuming a double-linked list, but that the linked list is not circular. That is, the "head" and "tail" nodes are not directly linked with each other. That is, head.getprev() and tail.getnext() both return None. Please review the course slides for the definition of a double-ended queue (deque) data structure. A working example of a singly-linked list can also be found in the course notes. For a deque, don't forget to consider both the "head" and "tail" when updating the object! Also note that for a length-one deque, the head and the tail will be the same node. A class for a node in a doubly-linked list, storing a data payload and links to next and previous nodes. IIIII Deque: \#\#\# Problem 5 def find(self, value): Finds the index of the given value in the deque. param value: The value to search for in the deque. returns: The index of the value if it exists; otherwise, None. pass Problem 5 Define the method Deque.find(self, value) satisfying the following criteria: - Find and return the index (as an offset) of the given value in the deque - If the value does not exist in the deque, return None Examples: In : y= Deque () In : y.push_back (1.11) In : y.push_back (2.22) In : y.push_back (3.33) In : print(y) 1.112.223.33 In : yfind(1.11) Out: 0 In : y.find(2.22) Out: 1 In : y.find("a") \# returns None (not printed)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started