mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 09:06:51 +08:00
Add tests Generic Heap and add check null item (#5801)
This commit is contained in:
@ -9,6 +9,10 @@ public class GenericHeap<T extends Comparable<T>> {
|
||||
HashMap<T, Integer> map = new HashMap<>();
|
||||
|
||||
public void add(T item) {
|
||||
if (item == null) {
|
||||
throw new IllegalArgumentException("Cannot insert null into the heap.");
|
||||
}
|
||||
|
||||
this.data.add(item);
|
||||
map.put(item, this.data.size() - 1); //
|
||||
upHeapify(this.data.size() - 1);
|
||||
|
Reference in New Issue
Block a user