Created
June 6, 2023 13:36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
class Deque: | |
def __init__(self): | |
self.items = deque() | |
def add_front(self, item): | |
self.items.appendleft(item) | |
def add_rear(self, item): | |
self.items.append(item) | |
def remove_front(self): | |
if not self.is_empty(): | |
return self.items.popleft() | |
def remove_rear(self): | |
if not self.is_empty(): | |
return self.items.pop() | |
def is_empty(self): | |
return len(self.items) == 0 | |
def size(self): | |
return len(self.items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment