Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote