diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eecc53..7ad1556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.6.0] - 2023-11-25 +## [3.6.2] - 2023-11-26 +### Changed +- Fix EnqueueDequeue + +## [3.6.1] - 2023-11-25 ### Changed - Fix doc of FloorSum diff --git a/Directory.Build.props b/Directory.Build.props index 311c35e..55d954a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,8 +7,8 @@ https://github.com/kzrnm/ac-library-csharp https://github.com/kzrnm/ac-library-csharp/blob/main/CHANGELOG.md - 3.6.1 - 3.6.1.101 + 3.6.2 + 3.6.2.101 $(GIT_COMMIT) True diff --git a/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp.cs b/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp.cs index bfbe24a..953b425 100644 --- a/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp.cs +++ b/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp.cs @@ -69,7 +69,7 @@ public T Dequeue() public T EnqueueDequeue(T value) { var res = data[0]; - if (_comparer.Compare(value, res) <= 0) + if (Count == 0 || _comparer.Compare(value, res) <= 0) { return value; } diff --git a/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp`2.cs b/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp`2.cs index 12bf2c9..8153f5b 100644 --- a/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp`2.cs +++ b/Source/ac-library-csharp/STL/PriorityQueue/PriorityQueueOp`2.cs @@ -91,7 +91,7 @@ public KeyValuePair Dequeue() public KeyValuePair EnqueueDequeue(TKey key, TValue value) { var res = KeyValuePair.Create(keys[0], values[0]); - if (_comparer.Compare(key, keys[0]) <= 0) + if (Count == 0 || _comparer.Compare(key, keys[0]) <= 0) { return KeyValuePair.Create(key, value); } diff --git a/Test/ac-library-csharp.Test/STL/PriorityQueueTest.cs b/Test/ac-library-csharp.Test/STL/PriorityQueueTest.cs index 026741c..98ca2a5 100644 --- a/Test/ac-library-csharp.Test/STL/PriorityQueueTest.cs +++ b/Test/ac-library-csharp.Test/STL/PriorityQueueTest.cs @@ -216,6 +216,9 @@ public void EnqueueDequeue() { var pq1 = new PriorityQueue(); var pq2 = new PriorityQueue(); + + pq1.EnqueueDequeue(1).Should().Be(1); + for (int i = 10; i > 0; i--) { pq1.Enqueue(i); @@ -242,6 +245,9 @@ public void EnqueueDequeueKV() { var pq1 = new PriorityQueueDictionary(); var pq2 = new PriorityQueueDictionary(); + + pq1.EnqueueDequeue(1, "ab").Should().Be(KeyValuePair.Create(1, "ab")); + for (int i = 10; i > 0; i--) { pq1.Enqueue(i, i.ToString());