Skip to content

Instantly share code, notes, and snippets.

@TheAlchemistKE
Created June 6, 2023 13:36
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