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
41
42
43
44
45
46
47
import java.util.*;
 
/** A max heap of times, with associated names for each time value. */
public class TimeHeap {
  /** A single (time,name) entry in the heap.
   * Note that when you are doing heap operations, you will be comparing
   * the "time" field in each entry.
   */
  private class Entry {
    public long time;
    public String name;
    public Entry(long time, String name) {
      this.time = time;
      this.name = name;
    }
  }
 
  // TODO: An array or ArrayList to store your heap
  // Perhaps you also want to store the size?
 
  /** Creates a new, empty heap. */
  public TimeHeap() {
    // TODO: initialize your heap with size 0
    // (hint: the array or arraylist should NOT be empty!)
  }
 
  /** Returns the number of entries in the heap */
  public int size() {
    // TODO
  }
 
  /** Inserts a new time and corresponding name to the heap. 
   * You can assume the name is not null. */
  public void insert(long time, String name) {
    // TODO
  }
 
  /** Removes the entry with the largest time, and returns the
   * corresponding name.
   */
  public String removeMax() {
    if (size() < 1) 
      throw new NoSuchElementException("heap is empty");
 
    // TODO
  }
}