FileDocCategorySizeDatePackage
Heap1.javaAPI DocExample1459Sat Sep 12 03:01:00 BST 1998None

Heap1

public class Heap1 extends Object
Making a heap, pushing and popping elements, sorting a heap.
see
com.objectspace.jgl.algorithms.Heap
version
3.0.0
author
ObjectSpace, Inc.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    Deque deque = new Deque();
    deque.add( "bat" );
    deque.add( "ape" );
    deque.add( "fox" );
    deque.add( "cat" );
    BinaryPredicate comparator = new LessString();
    Heap.makeHeap( deque.begin(), deque.end(), comparator );
    deque.add( "dog" );
    Heap.pushHeap( deque.begin(), deque.end(), comparator );
    deque.add( "emu" );
    Heap.pushHeap( deque.begin(), deque.end(), comparator );
    while ( !deque.isEmpty() )
      {
      System.out.println( deque.front() );
      Heap.popHeap( deque.begin(), deque.end(), comparator );
      deque.popBack();
      }

    Array vector = new Array();
    vector.add( "bat" );
    vector.add( "ape" );
    vector.add( "fox" );
    vector.add( "cat" );
    vector.add( "dog" );
    vector.add( "emu" );
    System.out.println( "unsorted vector = " + vector );
    Heap.makeHeap( vector.begin(), vector.end(), comparator );
    Heap.sortHeap( vector.begin(), vector.end(), comparator );
    System.out.println( "sorted vector = " + vector );