Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You'll have to create a <code>QueueSet</code> that implements <code>ICollection&lt;T&gt;</code>. It can be a wrapper class that contains a collection as a backing store. It can be implemented as follows:</p> <pre><code>class QueueSet&lt;T&gt; : ICollection&lt;T&gt; { List&lt;T&gt; queue=new List&lt;T&gt;(); int maximumSize; public QueueSet(int maximumSize){ if(maximumSize&lt;0) throw new ArgumentOutOfRangeException("maximumSize"); this.maximumSize=maximumSize; } public T Dequeue(){ if(queue.Count&gt;0){ T value=queue[0]; queue.RemoveAt(0); return value; } return default(T); } public T Peek(){ if(queue.Count&gt;0){ return queue[0]; } return default(T); } public void Enqueue(T item){ if(queue.Contains(item)){ queue.Remove(item); } queue.Add(item); while(queue.Count&gt;maximumSize){ Dequeue(); } } public int Count { get { return queue.Count; } } public bool IsReadOnly { get { return false; } } public void Add(T item) { Enqueue(item); } public void Clear() { queue.Clear(); } public bool Contains(T item) { return queue.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { foreach(T value in queue){ if(arrayIndex&gt;=array.Length)break; if(arrayIndex&gt;=0){ array[arrayIndex]=value; } arrayIndex++; } } public bool Remove(T item) { if(Object.Equals(item,Peek())){ Dequeue(); return true; } else { return false; } } public IEnumerator&lt;T&gt; GetEnumerator() { return queue.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return queue.GetEnumerator(); } } </code></pre> <p>I release this code into the public domain.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload