first commit -push
This commit is contained in:
23
RobotNet.RobotManager/Services/Planner/PriorityQueue.cs
Normal file
23
RobotNet.RobotManager/Services/Planner/PriorityQueue.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace RobotNet.RobotManager.Services.Planner;
|
||||
|
||||
public class PriorityQueue<T>(Comparison<T> comparison)
|
||||
{
|
||||
public List<T> Items => items;
|
||||
private readonly List<T> items = [];
|
||||
|
||||
public void Enqueue(T item)
|
||||
{
|
||||
items.Add(item);
|
||||
items.Sort(comparison);
|
||||
}
|
||||
|
||||
public T Dequeue()
|
||||
{
|
||||
if (items.Count == 0) throw new InvalidOperationException("Queue is empty");
|
||||
var item = items[0];
|
||||
items.RemoveAt(0);
|
||||
return item;
|
||||
}
|
||||
|
||||
public int Count => items.Count;
|
||||
}
|
||||
Reference in New Issue
Block a user