我是靠谱客的博主 虚拟柚子,这篇文章主要介绍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…内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复