University of Cincinnati logo and link  
Data Structures
 

 

Stacks and Queues

  A stack allows you to enter data only at the top of the collection.  Items are removed at the top of the stack as well, resutling in LIFO processing order.  The addition and removal operations are traditionally called push and pop.

Queues are similar to stacks, except queues act in a FIFO (First In, First Out) order.  That is, items are added to the end of the queue (the tail), and removed from the other end of the queue (the head). 

How are queues used in computer programming?
  • In Java, swing uses an event queue to process user input. As you enter keystrokes or click the mouse, the events are placed in a queue.  A thread takes items from the queue and processes them.
  • If you have a shared printer, you are probably familiar with a print queue.