
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
612
|
Chapter 11: Data Structures and Algorithms
11.3 Creating a Double Queue
Problem
You need a queue object in which you can explicitly control the adding and remov-
ing of objects to either the head (top) or tail (bottom), also known as a double queue.
Solution
A queue that allows explicit removal of items from the head and the tail is called a
double queue.
Example 11-4 shows one way you can implement a double queue.
Example 11-4. DblQueue class
using System;
using System.Collections;
using System.Collections.Generic;
[Serializable]
public class DblQueue<T> : ICollection<T>, ICloneable
{
public DblQueue( )
{
internalList = new List<T>( );
}
public DblQueue(ICollection<T> coll)
{
internalList = new List<T>(coll);
}
protected List<T> internalList = null;
public virtual int Count
{
get {return (internalList.Count);}
}
public virtual bool IsSynchronized
{
get {return (false);}
}
public virtual object SyncRoot
{
get {return (this);}
}