AI Horizon: Intelligence and Reason in Computers
Introduction Home Essays Resources Contact Info
  Basic CS
General AI
Chess AI

  Source Code
AI Tips and Tricks

  Code Journal
Site Updates

An Affiliate of

Queue Source Code
(Up to Resources : Source Code Repository : Lists)

This source file is an implementation of the Queue class. The class is implemented with templates, and the size is determined dynamically at initialization (although the default is 500 elements).

For the templated class, the elements must have the operators >, =, and < defined.

The actual amount of space allocated for the Queue will be one more element than the defined maximum size. This is useful for implementing the Queue in a circular method.

To understand the circular implementation, think of the array as a circle. When an element is dequeued, the Queue doesn't shift all of the elements forward to the start of the queue. Instead, the class shifts the start of the queue back. Eventually, the start of the queue will have shifted so far that the queue will extend beyond the end of the array. This is where the circle comes in. When the queue reachs the end of the array, it wraps around to the beginning of the array.

Download the Source: queue.h

All content is written and published by the people at or affiliated with AI Horizon <>.
Send any comments and suggestions to

Please report any errors to