using System; using System.Collections; using System.Collections.Generic; namespace Engine.Models { public class PriorityQueue : ICollection, IEnumerable { public PriorityQueue(IComparer comparer) { this.list = new List(); this.comparer = comparer; } public List List { get { return this.list; } } public void Enqueue(V value) { this.list.Add(value); this.list.Sort(this.comparer); } public V Dequeue() { if (this.list.Count == 0) { throw new Exception("Queue is empty!"); } V result = this.list[0]; this.list.RemoveAt(0); return result; } public void Remove(V element) { this.list.Remove(element); } public void CopyTo(Array array, int index) { throw new NotImplementedException(); } public int Count { get { return this.list.Count; } } public object SyncRoot { get { throw new NotImplementedException(); } } public bool IsSynchronized { get { throw new NotImplementedException(); } } public IEnumerator GetEnumerator() { return this.list.GetEnumerator(); } private List list; private IComparer comparer; } }