-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeap.java
More file actions
41 lines (29 loc) · 684 Bytes
/
Heap.java
File metadata and controls
41 lines (29 loc) · 684 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
30
31
32
33
34
35
36
37
38
39
40
import java.util.TreeSet;
class Heap {
private TreeSet<Integer> set;
Heap() {
this.set = new TreeSet<Integer>();
}
public int size() {
return this.set.size();
}
public boolean empty() {
return this.set.isEmpty();
}
public void insert(int v) {
this.set.add((Integer)v);
}
public int deleteMin() {
int min = this.set.first();
this.set.remove(this.set.first());
return min;
}
public int findMin() {
if (this.empty())
return -1;
return (int)(this.set.first());
}
public void delete(int i) {
this.set.remove((Integer)i);
}
}