当前位置:网站首页>Simple example of class template
Simple example of class template
2022-06-30 06:14:00 【Qiu cute】
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;
template<class Type>
class Queue {
public:
int real,length,maxSize;
Type *q;
Queue() {
this->real= -1;
this->length = 0;
this->maxSize = 0;
this->q = NULL;
}
Queue(int maxSize) {
this->real = -1;
this->length = 0;
this->maxSize = maxSize;
this->q = new Type(maxSize);
}
bool isFull() {
return length == maxSize;
}
bool isEmpty() {
return length == 0;
}
void add(Type t);
Type del();
void print(){
for(int i = 0 ; i < length;i++){
cout<<q[i]<<" ";
}
}
};
//Queue Scope specified first <> Specify the type
template<class Type>
void Queue<Type>::add(Type t) {
if(isFull()) {
return ;
}
real = (real+1)%maxSize;
length++;
q[real] = t;
}
template<class Type>
Type Queue<Type>::del() {
if(isEmpty()) {
return;
}
int ft = (real+1+maxSize-length)%maxSize;
length--;
return q[ft];
}
int main() {
Queue<int> q(5);
q.add(1);
q.print();
}
边栏推荐
猜你喜欢

文件操作IO-Part1

Develop stylelint rules from zero (plug-ins)

Completabilefuture: from understanding to mastering, here are all you want to know

Summary of redis learning notes (I)

Base64详解:玩转图片Base64编码

How does Altium designer hide some temporarily unnecessary classes, such as GND

MySQL 索引

CompletionService使用及原理(源码分析)

Base64 explanation: playing with pictures Base64 encoding

Dynamic routing job
随机推荐
Share problems solved
Completabilefuture: from understanding to mastering, here are all you want to know
InputStream to inputstreamsource
MySQL存储系统
PC viewing WiFi password
Usage of case, casez and casex statements in Verilog
uniapp 微信小程序返回上一页并刷新
[GPU] basic operation
Ultra simple STM32 RTC alarm clock configuration
Application of redis client list in practice
重构之美:当多线程批处理任务挑起大梁 - 万能脚手架
New project folder based on PIO plug-in in vscode -- Interpretation
File operation io-part1
InputStream转InputStreamSource
STM32F103 series controlled OLED IIC 4-pin
我做功能测试这么多年的心得
Master slave synchronization of MySQL database to realize read-write separation
SparseArray
MySQL transaction
Create uiactionsheet [duplicate] - creating uiactionsheet [duplicate]