Implementing a Queue - Source Co…
来源:互联网 发布:饥荒怎么修改数据 编辑:程序博客网 时间:2024/05/06 01:50
Implementing a Queue - Source Code
by Eric SuhThis source file is an implementation of the Queue class. The classis implemented with templates, and the size is determineddynamically at initialization (although the default is 500elements).
For the templated class, the elements must have the operators<, =, and >defined.
The actual amount of space allocated for the Queue will be one moreelement than the defined maximum size. This is useful forimplementing the Queue in a circularmethod.
To understand the circular implementation, think of the array as acircle. When an element is dequeued, the Queue doesn't shift all ofthe elements forward to the start of the queue. Instead, the classshifts the start of the queue back. Eventually, the start of thequeue will have shifted so far that the queue will extend beyondthe end of the array. This is where the circle comes in. When thequeue reaches the end of the array, it wraps around to thebeginning of the array.
The actual amount of space allocated for the Queue will be one moreelement than the defined maximum size. This is useful forimplementing the Queue in a circularmethod.
To understand the circular implementation, think of the array as acircle. When an element is dequeued, the Queue doesn't shift all ofthe elements forward to the start of the queue. Instead, the classshifts the start of the queue back. Eventually, the start of thequeue will have shifted so far that the queue will extend beyondthe end of the array. This is where the circle comes in. When thequeue reaches the end of the array, it wraps around to thebeginning of the array.
/ * Code provided by Eric Suh
*/
#ifndef __QueueClassH__
#define __QueueClassH__
#include <assert.h> // For error-checkingpurposes
//-------------------------------------------------
// Main structure of Queue Class:
//-------------------------------------------------
template <class Elem>
class Queue
{
};
//-------------------------------------------------
// Implementation of Queue Class:
//-------------------------------------------------
// Queue Constructor function
template <class Elem>
Queue<Elem>::Queue(int MaxSize):
{
}
// Queue Copy Constructor function
template <class Elem>
Queue<Elem>::Queue(const Queue&OtherQueue) :
{
}
// Queue Destructor function
template <class Elem>
Queue<Elem>::~Queue(void)
{
}
// Enqueue() function
template <class Elem>
void Queue<Elem>::Enqueue(constElem &Item)
{
}
// Dequeue() function
template <class Elem>
ElemQueue<Elem>::Dequeue(void)
{
}
// ElemNum() function
template <class Elem>
inline intQueue<Elem>::ElemNum(void)
{
}
#endif
- Implementing a Queue - Source Co…
- Full queue, lose …
- HDOJ 1017 A Mathematical Cur…
- HDOJ 4245 A Famous Music Comp…
- #define A (* (volatile unsigned …
-  
- Check a loop in a list with line…
- How to pass a hash to a subrouti…
-
- Writing a Simple …
- how to do with a slow oracle dat…
- How to get a good idea to perfor…
- How GNU Radio Core Works -- An A…
- POJ 1005 I Think I Need a Houseb…
- tomorrow I will have a trip to W…
- GVF - a new snake algorithm for …
- How to sign a Driver by Windows …
- configure: error: C co
- 命令列引數
- C++ 參考(Reference)
- auto_ptr 自動管理配置資源
- struts2中namespace与jsp页面请求action路径对应关系
- stack implement C++
- Implementing a Queue - Source Co…
- windows 7 设置环境变量的方法
- 成功安装cadence SPB16.0
- iOS开发资源:Helios、THLabel以及AGi18n等
- GNU Automake By Example
- 数据库的备份与还原
- svn文件丢失的解法
- sh脚本异常:/bin/sh^M:bad interp…
- 网页乱码的解决办法