|
- using System;
- using System.Collections;
- using System.Collections.Generic;
-
- namespace Engine.Models
- {
- public class PriorityQueue<V> : ICollection, IEnumerable
- {
- public PriorityQueue(IComparer<V> comparer)
- {
- this.list = new List<V>();
- this.comparer = comparer;
- }
-
- public List<V> 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<V> list;
-
- private IComparer<V> comparer;
- }
- }
|