我是靠谱客的博主 虚拟柚子,最近开发中收集的这篇文章主要介绍Implementing a Queue - Source Co… Implementing a Queue - Source Code,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
Implementing a Queue - Source Code
by Eric SuhThis 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 reaches the end of the array, it wraps around to the beginning of the array.
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 reaches the end of the array, it wraps around to the beginning of the array.
/ * Code provided by Eric Suh
*/
#ifndef __QueueClassH__
#define __QueueClassH__
#include <assert.h>
// For error-checking purposes
//-------------------------------------------------
// 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(const Elem &Item)
{
}
// Dequeue() function
template <class Elem>
Elem Queue<Elem>::Dequeue(void)
{
}
// ElemNum() function
template <class Elem>
inline int Queue<Elem>::ElemNum(void)
{
}
#endif
最后
以上就是虚拟柚子为你收集整理的Implementing a Queue - Source Co… Implementing a Queue - Source Code的全部内容,希望文章能够帮你解决Implementing a Queue - Source Co… Implementing a Queue - Source Code所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复