//【数据结构】用C++编写队列及基本操作(包括插入,出队列,摧毁,清空等等)
//头文件
#ifndef _SEQ_STACK_
#define _SEQ_STACK_
#include <iostream>
using namespace std;
template <class Type>
class Queue
{
public:
Queue(size_t sz = INIT_SIZE)
{
capacity = sz > INIT_SIZE ? sz : INIT_SIZE;
base = new Type[capacity];
front = back = 0;
}
~Queue()
{
destory();
}
public:
bool empty() const //判断是否为空
{
return(front==back);
}
bool full()const //判断是否已满
{
return((back+1)%capacity==front);
}
public:
void push(const Type &x) //进队列
{
if (full())
{
cout << "队列已满,不能插入。" << endl;
return;
}
base[back] = x;
back = (back + 1) % capacity;
}
void pop() //出队列
{
if (empty())
{
cout << "队列为空" << endl;
return;
}
front=(front+1)%capaci
【数据结构】用C++编写队列及基本操作(包括插入,出队列,摧毁,清空等等)
最新推荐文章于 2024-06-08 18:30:35 发布