public class Heap extends Object
Elements of this data structure should either implement Comparable, or a Comparator should be given as argument to the constructor.
Constructor and Description |
---|
Heap()
Creates a new Heap whose elements inserted implement the
Comparable interface. |
Heap(Comparator comparator)
Creates a new Heap whose elements are compared using the given
Comparator . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Empties this heap
|
protected int |
compare(Object o1,
Object o2) |
Object |
extract()
Removes and returns the least element of this heap.
|
void |
insert(Object obj)
Inserts the given element in this heap.
|
protected int |
left(int index) |
protected int |
parent(int index) |
Object |
peek() |
protected int |
right(int index) |
public Heap()
Comparable
interface.public Heap(Comparator comparator)
Comparator
.comparator
- public void insert(Object obj)
obj
- extract()
public Object extract()
insert(java.lang.Object)
,
peek()
public Object peek()
extract()
public void clear()
protected int parent(int index)
index
- index
.protected int left(int index)
index
- index
.protected int right(int index)
index
- index
.Copyright © 2018 JBoss by Red Hat. All rights reserved.