summaryrefslogtreecommitdiffstats
path: root/Heap.cs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-03-29 22:06:57 +0000
committerToby Vincent <tobyv13@gmail.com>2021-03-29 22:06:57 +0000
commit8a056874d97a210f1bd48e8045d548061683ab7f (patch)
tree75cb37d5325fbbe46ea444db48e2f7c93125728d /Heap.cs
parentb0981d54a1a599d11b2c78a5a734071e7cbf8abe (diff)
refactored and clean up some functions
Diffstat (limited to 'Heap.cs')
-rwxr-xr-xHeap.cs8
1 files changed, 4 insertions, 4 deletions
diff --git a/Heap.cs b/Heap.cs
index 339afc8..6402de4 100755
--- a/Heap.cs
+++ b/Heap.cs
@@ -40,18 +40,18 @@ namespace PriorityQueue
Array[other] = temp;
}
- protected int CompareKey(T that, T other) =>
- that.CompareTo(other) * (IsMin ? -1 : 1);
+ protected bool MoreSignificant(T that, T other) =>
+ that.CompareTo(other) * (IsMin ? -1 : 1) > 0;
// build local heap
protected void Heapify(int index)
{
int sig = index;
- if (Left(index) <= HeapSize && CompareKey(Array[Left(index)], Array[sig]) > 0)
+ if (Left(index) <= HeapSize && MoreSignificant(Array[Left(index)], Array[sig]))
sig = Left(index);
- if (Right(index) <= HeapSize && CompareKey(Array[Right(index)], Array[sig]) > 0)
+ if (Right(index) <= HeapSize && MoreSignificant(Array[Right(index)], Array[sig]))
sig = Right(index);
if (sig != index)