Skip to content
Anthony Christe edited this page Oct 11, 2013 · 2 revisions

Description

  • FIFO
  • Perfect line
  • Useful in many data management situations

Queue ADT

  • 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

Array Implementation

  • 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)

In-lab exercise

  • Show how you can use two stacks to create a queue
  • Show how you can use two queues to create a stack

Clone this wiki locally