home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
Heap1.java
< prev
next >
Wrap
Text File
|
1997-07-30
|
1KB
|
48 lines
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
/**
* Making a heap, pushing and popping elements, sorting a heap.
*
* @see COM.objectspace.jgl.Heap
* @version 2.0.2
* @author ObjectSpace, Inc.
*/
public class Heap1
{
public static void main( 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 );
}
}