Create a stack implementation using deques in order to run using the following o
ID: 3731521 • Letter: C
Question
Create a stack implementation using deques in order to run using the following outline using python. Take into consideration any special cases. Using push_front to add onto the stack, pop_front to remove from a stack and peek_front to peek at a stack.
class Stack:
def __init__(self):
self._deque = Deque()
def __str__(self):
return str(self._deque)
def __len__(self):
return len(self._deque)
def push(self, val):
#implement code here
def pop(self):
#implement code here
def peek(self):
#implement code here
Explanation / Answer
I am adding the definition for not implemented code
def push(self, val):
self.deque.push_front(val)
def pop(self) :
if ( self.deque ) :
self.deque.pop_front()
def peek(self):
if ( self.deque ):
return (self.deque)[0]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.