-
Notifications
You must be signed in to change notification settings - Fork 4
Queues
Anthony Christe edited this page Oct 11, 2013
·
2 revisions
- FIFO
- Perfect line
- Useful in many data management situations
- offer(E e) - Adds an item to the end queue
- E peek() - Returns, but does not remove an item from the front of the queue
- E poll() - Returns and removes an item from the front of the queue
- Java's Queue
- Keep track of two pointers, front and end
- Set front and end initially to 0
- On offer, insert at end, and increment end
- On poll, return front, and increment front
- Allow both front and end to wrap around array (use modulus)
- Show how you can use two stacks to create a queue
- Show how you can use two queues to create a stack