Guest User

Python deque implementation

a guest
Sep 21st, 2011
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class deque:
  2.     def __init__(self):
  3.         self._data = []
  4.  
  5.     def add_front(self, i):
  6.         self._data.insert(0, i)
  7.  
  8.     def add_back(self, i):
  9.         self._data.append(i)
  10.  
  11.     def remove_front(self):
  12.         return self._data.pop(0)
  13.  
  14.     def remove_back(self):
  15.         return self._data.pop()
  16.  
  17.     def front(self):
  18.         return self._data[0]
  19.  
  20.     def back(self):
  21.         return self._data[-1]
  22.  
  23.     def is_empty(self):
  24.         return len(self._data) == 0
  25.  
  26.     def __str__(self):
  27.         return self._data.__str__()
RAW Paste Data