All Packages  Class Hierarchy  Previous  Next  Index

Queue Examples

Queue 1 - Construction, enumeration, pushing, popping.

Queue 2 - Use of List as underlying Sequence.


Queue1 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.

import java.util.Enumeration;
import COM.objectspace.jgl.*;

/**
 * Construction, enumeration, pushing, popping.
 *
 * @see COM.objectspace.jgl.Queue
 * @version 2.0.2
 * @author ObjectSpace, Inc.
 */

public class Queue1
  {
  public static void main( String[] args )
    {
    // Use an SList as the underlying data structure.
    Queue queue = new Queue();
    queue.push( "bat" );
    queue.push( "cat" );
    queue.push( "dog" );

    System.out.println( "Print the Queue." );
    System.out.println( queue );
    System.out.println();

    System.out.println( "Non-destructively enumerate the Queue." );
    Enumeration e = queue.elements();
    while ( e.hasMoreElements() )
      System.out.println( e.nextElement() );
    System.out.println();

    System.out.println( "Pop and print each element." );
    while ( !queue.isEmpty() )
      System.out.println( queue.pop() );
    }
  }

Queue1 Example Output

Print the Queue.
Queue( SList( bat, cat, dog ) )

Non-destructively enumerate the Queue.
bat
cat
dog

Pop and print each element.
bat
cat
dog

Queue2 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.

import COM.objectspace.jgl.*;

/**
 * Use of List as underlying Sequence.
 *
 * @see COM.objectspace.jgl.Queue
 * @version 2.0.2
 * @author ObjectSpace, Inc.
 */

public class Queue2
  {
  public static void main( String[] args )
    {
    // Use a DList as the underlying data structure.
    Queue queue = new Queue( new DList() );
    queue.push( "bat" );
    queue.push( "cat" );
    queue.push( "dog" );

    System.out.println( "Print the queue." );
    System.out.println( queue );
    }
  }

Queue2 Example Output

Print the queue.
Queue( DList( bat, cat, dog ) )

All Packages  Class Hierarchy  Previous  Next  Index