Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
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);}
}
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating a Double Queue
|
613
public virtual void Clear( )
{
internalList.Clear( );
}
public object Clone( )
{
// Make a new DblQueue.
DblQueue<T> newDQ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata