diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-03-29 22:06:57 +0000 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-03-29 22:06:57 +0000 |
commit | 8a056874d97a210f1bd48e8045d548061683ab7f (patch) | |
tree | 75cb37d5325fbbe46ea444db48e2f7c93125728d /Heap.cs | |
parent | b0981d54a1a599d11b2c78a5a734071e7cbf8abe (diff) |
refactored and clean up some functions
Diffstat (limited to 'Heap.cs')
-rwxr-xr-x | Heap.cs | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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)
|