All Packages  Class Hierarchy  Previous  Next  Index

Rotating Examples

Rotating 1 - Rotating a JGL container, copy during rotate.


Rotating1 Example Code

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

import COM.objectspace.jgl.*;

/**
 * Rotating a JGL container, copy during rotate.
 *
 * @see COM.objectspace.jgl.Rotating
 * @version 2.0.2
 * @author ObjectSpace, Inc.
 */

public class Rotating1
  {
  public static void main( String[] args )
    {
    Array array1 = new Array();
    for ( int i = 0; i < 5; i++ )
      array1.add( new Integer( i ) );
    for ( int i = 0; i < array1.size(); i++ )
      {
      Array array2 = new Array( array1 );
      ArrayIterator p = array2.begin();
      p.advance( i );
      Rotating.rotate( array2.begin(), p, array2.end() );
      System.out.println( "Rotate around index " + i + ", " + array1 + " -> " + array2 );
      }

    Deque d = new Deque();
    ArrayIterator q = array1.begin();
    q.advance( 1 );
    Rotating.rotateCopy( array1.begin(), q, array1.end(), new InsertIterator( d ) );
    System.out.println( "Rotate around index 2, " + array1 + " -> " + d );
    }
  }

Rotating1 Example Output

Rotate around index 0, Array( 0, 1, 2, 3, 4 ) -> Array( 0, 1, 2, 3, 4 )
Rotate around index 1, Array( 0, 1, 2, 3, 4 ) -> Array( 1, 2, 3, 4, 0 )
Rotate around index 2, Array( 0, 1, 2, 3, 4 ) -> Array( 2, 3, 4, 0, 1 )
Rotate around index 3, Array( 0, 1, 2, 3, 4 ) -> Array( 3, 4, 0, 1, 2 )
Rotate around index 4, Array( 0, 1, 2, 3, 4 ) -> Array( 4, 0, 1, 2, 3 )
Rotate around index 2, Array( 0, 1, 2, 3, 4 ) -> Deque( 1, 2, 3, 4, 0 )

All Packages  Class Hierarchy  Previous  Next  Index