Professional Documents
Culture Documents
The
bubbleUp
helper
peek is O(1)
peek on a max-heap would be O(1) as well, but would return
you the maximum element
10
20
40
50
4
80
60
700 65
85
99
10
20
40
700
6
50
65
80
60
65
85
20
99
40
700
50
80
60
65
85
99
65
20
40
700
7
50
20
80
60
85
40
99
50
700
65
80
60
85
99
42
50 55
6
11
88 20
104
10
i * 2; }
i * 2 + 1; }
return leftIndex(i) <= size; }
return rightIndex(i) <= size; }
11
PrintJob Class
public class PrintJob {
private String user;
private int number;
private int priority;
public PrintJob(int number, String user, int priority) {
this.number = number;
this.user = user;
this.priority = priority;
}
public String toString() {
return this.number + " (" + user + "):" + this.priority;
}
}
13
14
Implementing generics
// a parameterized (generic) class
public class name<Type> {
...
}
By putting the Type in < >, you are demanding that any
client that constructs your object must supply a type
parameter.
The rest of your class's code can refer to that type by name.
15