-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeap.java
More file actions
29 lines (26 loc) · 860 Bytes
/
Heap.java
File metadata and controls
29 lines (26 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
/**
* A data structure that implements a maximum heap. The heap's internal storage
* should be based on a standard Java array.
*/
interface Heap<T extends Comparable<? super T>> {
/**
* Adds the specified item to the heap.
* This operation must run in logarithmic time <em>O</em>O(log <em>n</em>), where <em>n</em>
* is the number of items currently stored in the heap.
* @param item the item to add
*/
void add (T item);
/**
* Removes and returns the currently "largest" item from the heap (which is always at the top).
* This operation must run in constant time.
* @return the top of the heap
*/
T removeFirst ();
/**
* Returns the number of items currently stored in the heap.
* This operation must run in constant time.
* @return the number of items currently stored in the heap.
*/
int size ();
}