头文件:
#pragma once
#include <iostream>
#include <assert.h>
using namespace std;
template<class Type>
class SeqQueue
{
public:
SeqQueue(size_t sz = INIT_SZ);
~SeqQueue();
public:
bool empty()const;
bool full()const;
void show()const;
bool push(const Type &x);
bool pop();
void gettop(Type &x);
int length()const;
void clear();
void destory();
void quit_system(Type &x);
private:
enum{ INIT_SZ = 8 };
Type *base;
int capacity;
int head;
int tail;
};
template<class Type>
SeqQueue<Type>::SeqQueue(size_t sz = INIT_SZ)
{
capacity = sz > INIT_SZ ? sz : INIT_SZ;
base = new Type[capacity];
assert(base != NULL);
head = 0;
tail = 0;
}
template<class Type>
SeqQueue<Type>::~SeqQueue()
{
destory();
}
// 判断队列是否满了,顺序队列呈现虚满的状态
template<class Type>
bool SeqQueue<Type>::full()const
{
return (tail >