From 0f9defa6d1b564478e6ed1939a996065c61dd21a Mon Sep 17 00:00:00 2001 From: Sayyed Ali Kiaian Mousavy Date: Thu, 21 Feb 2019 18:08:09 +0100 Subject: [PATCH] Changed 2 functions in binaryheap.java Edited functions getHeadValue and toString in binaryHeapArray in file binaryheap.java to return null when size is 0 --- src/com/jwetherell/algorithms/data_structures/BinaryHeap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/jwetherell/algorithms/data_structures/BinaryHeap.java b/src/com/jwetherell/algorithms/data_structures/BinaryHeap.java index 81932349..9e1f25f0 100644 --- a/src/com/jwetherell/algorithms/data_structures/BinaryHeap.java +++ b/src/com/jwetherell/algorithms/data_structures/BinaryHeap.java @@ -341,7 +341,7 @@ public T[] getHeap() { */ @Override public T getHeadValue() { - if (array.length == 0) return null; + if (array.length == 0 || size == 0) return null; return array[0]; } @@ -372,7 +372,7 @@ public String toString() { protected static class HeapPrinter { public static > String getString(BinaryHeapArray tree) { - if (tree.array.length == 0) + if (tree.array.length == 0 || size == 0) return "Tree has no nodes."; T root = tree.array[0];