File tree 3 files changed +8
-0
lines changed
src/main/java/com/thealgorithms/datastructures/heaps
3 files changed +8
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ public HeapElement getElement(int elementIndex) {
43
43
44
44
// Get the key of the element at a given index
45
45
private double getElementKey (int elementIndex ) {
46
+ if ((elementIndex <= 0 ) || (elementIndex > maxHeap .size ())) {
47
+ throw new IndexOutOfBoundsException ("Index out of heap range" );
48
+ }
49
+
46
50
return maxHeap .get (elementIndex - 1 ).getKey ();
47
51
}
48
52
Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ public HeapElement getElement(int elementIndex) {
37
37
38
38
// Get the key of the element at a given index
39
39
private double getElementKey (int elementIndex ) {
40
+ if ((elementIndex <= 0 ) || (elementIndex > minHeap .size ())) {
41
+ throw new IndexOutOfBoundsException ("Index out of heap range" );
42
+ }
43
+
40
44
return minHeap .get (elementIndex - 1 ).getKey ();
41
45
}
42
46
You can’t perform that action at this time.
0 commit comments