Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Queues (FIFO) and stacks (LIFO)
- Python makes using queues and stacks a piece of cake (Did I already say "piece of cake" ?).
- No use creating a specific class: simply use list objects.
- """
- For a stack (LIFO), stack with append() and destack with pop():
- >>> a = [5,8,9]
- >>> a.append(11)
- >>> a
- [5, 8, 9, 11]
- >>> a.pop()
- 11
- >>> a.pop()
- 9
- >>> a
- [5, 8]
- >>>
- For a queue (FIFO), enqueue with append() and dequeue with pop(0):
- >>> a = [5,8,9]
- >>> a.append(11)
- >>> a
- [5, 8, 9, 11]
- >>> a.pop(0)
- 5
- >>> a.pop(0)
- 8
- >>> a
- [9, 11]
- """
- As lists can contain any type of object, you an create queues and stacks of any type of objects !
- (Note that there is also a Queue module, but it is mainly usefull with threads.)
- """
Advertisement
Add Comment
Please, Sign In to add comment