Created
March 21, 2021 18:43
-
-
Save Clivern/765b3d4dc59dc8cab8d29bd5e0177c66 to your computer and use it in GitHub Desktop.
Python Deque
This file contains hidden or 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
| class Deque(): | |
| """Deque DST""" | |
| def __init__(self): | |
| self._items = [] | |
| def add_front(self, item): | |
| """ | |
| Add to the front | |
| """ | |
| self._items.append(item) | |
| def add_rear(self, item): | |
| """ | |
| Add to the back | |
| """ | |
| self._items.insert(0, item) | |
| def remove_front(self): | |
| """ | |
| Remove from the front | |
| """ | |
| return self._items.pop() | |
| def remove_rear(self): | |
| """ | |
| Remove from the back | |
| """ | |
| return self._items.pop(0) | |
| def size(self): | |
| """ | |
| Get the size | |
| """ | |
| return len(self._items) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment