当前位置:网站首页>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();
}
边栏推荐
- 反編譯正常回編譯出現問題自己解决辦法
- One sentence introduction to Trojan horse
- 网络基础知识
- Share problems solved
- [deep learning] data segmentation
- Several commands not commonly used in MySQL
- [MD editing required] welcome to the CSDN markdown editor
- ES6 deconstruction assignment
- Navigate back to fragmentpageradapter - & gt; Fragment is empty - navigating back to fragmentpageradapter - & gt; fragments are empty
- 【微信小程序:单选、多选样式,背景色,圆角】
猜你喜欢

电脑查看WiFi使用密码

Intelligent question - horse racing question
![[GPU] basic operation](/img/76/6b22368e3addd30aef1dd2258ee49a.jpg)
[GPU] basic operation

JS prototype chain object function relationship

Verilog中case,casez,casex语句的用法

RSA and AES

圖像處理7-圖像增强

Base64 explanation: playing with pictures Base64 encoding
![[deep learning] data segmentation](/img/16/798881bbee66faa2fb8d9396155010.jpg)
[deep learning] data segmentation

Who doesn't want a blog site of their own - build a blog site WordPress
随机推荐
反编译正常回编译出现问题自己解决办法
46. full arrangement -dfs double hundred code
Ultra simple STM32 RTC alarm clock configuration
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
Mariadb数据库的安装与初始化
Decompilation normal decompilation problems. Solve them yourself
C language code record
File operation io-part1
Learn fpga---ram IP core and key parameters from the bottom structure
DOM (document object model) document XML file object model
PC viewing WiFi password
文件操作IO-Part1
【学习强化学习】总目录
图片。。。。。
圖像處理7-圖像增强
880. 索引处的解码字符串
Using C language pure for loop to implement ilovey
CompletableFuture从了解到精通,你想知道的这里都有
Create uiactionsheet [duplicate] - creating uiactionsheet [duplicate]
583. 两个字符串的删除操作-动态规划