Click here to Skip to main content
Licence 
First Posted 29 Mar 2004
Views 51,142
Bookmarked 15 times

A Dequeue - also called a ring-buffer

By | 29 Mar 2004 | Article
Another addition to the System.Collections - a ring buffer, more sophisticated than ArrayList or Queue.

Introduction

Dequeue means 'double-ended-queue'. All who remember the good old STL days will know exactly what it is. For all the others: it's a System.Collections-compatible class implementing a queue that supports Enqueue and Dequeue at both ends.

Usage

The main functions (in addition to all the System.Collections-brabble) are:

  • EnqueueHead, EnqueueTail for adding to the DQ
  • DequeueHead, DequeueTail for taking from the DQ
  • EnqueueHeadRange, EnqueueTailRange for adding a collection to the DQ (the order is preserved)

The DQ allows enumerations and indexed access. For that, you need to know that the 'head' of the DQ is always the element with index 0, the tail is always the element with the index (Count-1). Enumeration is in that order as well.

EnqueueHead/Tail- and DequeueHead/Tail-operations are O(1)-complex, except when the buffer has to be grown, which will take O(n) steps (naturally). So you can see that the buffer is faster than an ArrayList and more flexible than a Queue.

Example

Dequeue D = new Dequeue();
D.EnqueueTail("The");
D.EnqueueTail("big");
D.EnqueueTail("brown");
D.EnqueueTail("fox");
// now D is [The big brown fox ]
Dequeue D2 = new Dequeue();
D2.EnqueueHead("dog.");
D2.EnqueueHead("lazy");
D2.EnqueueHead("the");
D2.EnqueueHead("over");
D2.EnqueueHead("jumped");
// now D2 is [jumped over the lazy dog. ]
Dequeue D3 = new Dequeue();
D3.EnqueueTailRange(D2);
D3.EnqueueHeadRange(D);
// now D3 is [The big brown fox jumped over the lazy dog. ]

History

  • 30.3.04 - Inserted.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

BenDi

Web Developer

Germany Germany

Member

I did my diploma in Dresden and Sydney where I dealt with algorithms, agents and other cool AI stuff. Now I moved to Frankfurt to work on my PhD dealing with software structures for artificial intelligence systems. If I can, I do things in C# and ASP.NET, but if I have to, my C++, Java and SQL are not that bad.
Long Live .NET.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberzecanard6:11 22 Oct '10  
Generalbug found PinmemberGuggsdu0:01 13 Sep '04  
GeneralRe: bug found Pinmembermetalmonkey18:03 1 Jul '10  
Generalnot a ring buffer PinPopularmemberwyldeling9:19 30 Mar '04  
GeneralRe: not a ring buffer PinmemberBenDi9:57 30 Mar '04  
GeneralRe: not a ring buffer PinsussAnonymous16:21 18 Jun '04  
GeneralRe: not a ring buffer Pinmemberswampmonster14:01 25 Jul '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120528.1 | Last Updated 30 Mar 2004
Article Copyright 2004 by BenDi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid