-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyHeapEntry.java
More file actions
72 lines (62 loc) · 1.4 KB
/
MyHeapEntry.java
File metadata and controls
72 lines (62 loc) · 1.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package heap;
import net.datastructures.Entry;
import net.datastructures.Position;
/**
* Represents a key/value pair to be stored in a data
* structure, such as a heap. Entry<K,V> is a very
* limited accessing interface, so you may wish to add
* additional methods. In particular, think about the
* relationship of the Entry<K,V> to its location in
* the heap's binary tree. All methods must run in O(1)
* time.
*
* Feel free to add additional comments.
*/
public class MyHeapEntry<K,V> implements Entry<K,V> {
private K _key;
private V _value;
private Position<MyHeapEntry<K,V>> _position;
/**
* Default constructor. You may wish to modify the parameters.
*/
public MyHeapEntry(K key, V value) {
_key = key;
_value = value;
}
/**
* @return the key stored in this entry
*/
public K getKey() {
return _key;
}
/**
* @return the value stored in this entry
*/
public V getValue() {
return _value;
}
/**
* set the key stored in this entry
*/
public void setKey(K key) {
_key = key;
}
/**
* set the value stored in this entry
*/
public void setValue(V value) {
_value = value;
}
/**
* set the position of the entry
*/
public void setPosition(Position<MyHeapEntry<K,V>> position) {
_position = position;
}
/**
* @return the position that the entry is contained in
*/
public Position<MyHeapEntry<K, V>> getPosition() {
return _position;
}
}