diff --git a/SystemExtensions/Collections/BinaryHeap.cs b/SystemExtensions/Collections/BinaryHeap.cs index cc7cb2d..415c821 100644 --- a/SystemExtensions/Collections/BinaryHeap.cs +++ b/SystemExtensions/Collections/BinaryHeap.cs @@ -101,7 +101,7 @@ namespace SystemExtensions.Collections /// Removes the item at the root. Throws exception if there are no items in the heap. /// /// Value removed. - public T RemoveMinimum() + public T Remove() { if (count == 0) { @@ -113,6 +113,19 @@ namespace SystemExtensions.Collections return min; } /// + /// Peeks at the item at the root. Throws exception if there are no items in the heap. + /// + /// + public T Peek() + { + if (count == 0) + { + throw new IndexOutOfRangeException("Heap is empty!"); + } + T min = items[1]; + return min; + } + /// /// Return the heap structure as an array /// /// Array with values sorted as in heap diff --git a/SystemExtensions/Collections/PriorityQueue.cs b/SystemExtensions/Collections/PriorityQueue.cs index 76f507b..c3a54df 100644 --- a/SystemExtensions/Collections/PriorityQueue.cs +++ b/SystemExtensions/Collections/PriorityQueue.cs @@ -56,7 +56,7 @@ namespace SystemExtensions.Collections { if (Count > 0) { - return binaryHeap.RemoveMinimum(); + return binaryHeap.Remove(); } else { diff --git a/SystemExtensionsTests/Collections/BinaryHeapTests.cs b/SystemExtensionsTests/Collections/BinaryHeapTests.cs index 7240ebc..38b1c59 100644 --- a/SystemExtensionsTests/Collections/BinaryHeapTests.cs +++ b/SystemExtensionsTests/Collections/BinaryHeapTests.cs @@ -63,7 +63,7 @@ namespace SystemExtensions.Collections.Tests { Assert.Fail(); } - System.Diagnostics.Debug.WriteLine(binaryHeap.RemoveMinimum()); + System.Diagnostics.Debug.WriteLine(binaryHeap.Remove()); tries--; } }