Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stueue():
- def __init__(self):
- self._contents = []
- self._dequeue_top = True
- def put(self, item):
- self._contents.insert(0, item)
- def get(self):
- ret = None
- if not self.isempty():
- if self._dequeue_top:
- ret = self._contents.pop(0)
- else:
- ret = self._contents.pop(-1)
- self._dequeue_top = not self._dequeue_top
- return ret
- def peek(self):
- ret = None
- if not self.isempty():
- if self._dequeue_top:
- ret = self._contents[0]
- else:
- ret = self._contents[-1]
- return ret
- def is_empty(self):
- return(self._contents == [])
- def copy(self):
- su = Stueue()
- su._contents = self._contents
- su._dequeue_top = self._dequeue_top
- return su
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement