diff options
Diffstat (limited to 'PriorityQueue.cs')
-rwxr-xr-x | PriorityQueue.cs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/PriorityQueue.cs b/PriorityQueue.cs index d708f58..9dc2346 100755 --- a/PriorityQueue.cs +++ b/PriorityQueue.cs @@ -67,20 +67,20 @@ namespace PriorityQueue return sig;
}
- protected bool IsMoreSignificant(U that, U other) =>
- that.CompareTo(other) * (IsMin ? -1 : 1) > 0;
+ protected int CompareKey(U that, U other) =>
+ that.CompareTo(other) * (IsMin ? -1 : 1);
public void ChangeKey(int id, U key)
{
int index = Location[id];
// key <= Array[index].Key
- if (!IsMoreSignificant(key, Array[index].Key))
+ if (CompareKey(key, Array[index].Key) < 0)
throw new System.ArgumentException($"New key ({key}) is less significant than node {id}'s current key ({Array[index].Key}).");
Array[index].Key = key;
- while (index > 0 && IsMoreSignificant(Array[index], Array[Parent(index)]))
+ while (index > 0 && CompareKey(Array[index], Array[Parent(index)]) > 0)
{
Swap(index, Parent(index));
index = Parent(index);
|