Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class Stueue():
  2.  
  3. def __init__(self):
  4. self._contents = []
  5. self._dequeue_top = True
  6.  
  7. def put(self, item):
  8. self._contents.insert(0, item)
  9.  
  10. def get(self):
  11. ret = None
  12. if not self.isempty():
  13. if self._dequeue_top:
  14. ret = self._contents.pop(0)
  15. else:
  16. ret = self._contents.pop(-1)
  17. self._dequeue_top = not self._dequeue_top
  18. return ret
  19.  
  20. def peek(self):
  21. ret = None
  22. if not self.isempty():
  23. if self._dequeue_top:
  24. ret = self._contents[0]
  25. else:
  26. ret = self._contents[-1]
  27. return ret
  28.  
  29. def is_empty(self):
  30. return(self._contents == [])
  31.  
  32. def copy(self):
  33. su = Stueue()
  34. su._contents = self._contents
  35. su._dequeue_top = self._dequeue_top
  36. return su
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement