56.C++队列模版

#pragma once
//Queue.h
#ifndef QUEUE_H
#define QUEUE_H
#include<assert.h>
//类模板的定义
template<class T,int SIZE=50>
class Queue {
private:
	int front, rear, count;//队头指针,队尾指针,元素个数
	T list[SIZE];//队列元素数组

public:
	Queue();//构造函数,初始化队头指针,队尾指针,元素个数
	void insert(const T& item);//新元素入队
	T remove();//元素出队
	void clear();//清空队列
	const T getFront()const;//访问队首元素
	
	//测试队列状态
	int getLength()const;//求队列长度
	bool isEmpty()const;//判断队列是否为空
	bool isFull()const;//判断队列是否为满

};
#endif // !QUEUE_H


//类模板实现

//构造函数
template<class T, int SIZE>
Queue<T, SIZE>::Queue():front(0),rear(0),count(0){}

template<class T,int SIZE>
void Queue<T, SIZE>::insert(const T& item) {//向队尾插入元素item
	assert(count != SIZE);
	list[rear] = item;
	rear = (rear + 1) % SIZE;//队尾指针+1,取余实现循环队列
}

template<class T,int SIZE>
T Queue<T, SIZE>::remove() {
	assert(count != 0);
	int temp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值