Skip to main content
Lesson 39 - Queues
Lesson MenuPreviousNext
  
Operations on Queues page 4 of 8

  1. The following operations are supported by the Queue interface:

    public interface Queue
    {
      boolean isEmpty();
      void enqueue(Object obj);
      Object dequeue();
      Object peekFront();
    }
  2. Using a queue implemented through the Queue interface is very similar to using a stack. Here is a sample program that uses some of the key operations provided by a Queue implementation.

    Program 39-1

    public static void main(String[] args)
    {
      ListQueue queue;
    
      for (int k = 1; k <= 5; k++)
        queue.enqueue(new Integer(k));
    
      while (!queue.isEmpty())
      {
        System.out.println(queue.dequeue());
      }
    }
    
    Run output:
    
    1 2 3 4 5
  3. See Handout H.A.39.1, Queue Interface* for the full specifications of the Queue interface.


*Adapted from the College Board's AP Computer Science AB: Implementation Classes and Interfaces


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.