当前位置:网站首页>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();
}
边栏推荐
- To: k210 realizes face recognition (code interpretation attached)
- [deep learning] data segmentation
- Intelligent question - horse racing question
- 从底层结构开始学习FPGA----RAM IP核及关键参数介绍
- Network basics
- DHCP operation
- Create uiactionsheet [duplicate] - creating uiactionsheet [duplicate]
- MySQL index
- 从零开发 stylelint规则(插件)
- ES6 array traversal and Es5 array traversal
猜你喜欢

Gestion des utilisateurs de la base de données MySQL

Detailed description of methods in the interface

Using C language pure for loop to implement ilovey

【微信小程序:单选、多选样式,背景色,圆角】
![[ansible series] fundamentals 02 module debug](/img/99/c53be8e2a42c7cb5b4a9a7ef4ad98c.jpg)
[ansible series] fundamentals 02 module debug

Leetcode56. consolidation interval

圖像處理7-圖像增强

从零开发 stylelint规则(插件)
一个完整的性能测试流程

Mariadb数据库的安装与初始化
随机推荐
Summary of redis learning notes (I)
ES6 array
01. 正则表达式概述
Summation of basic exercise sequence of test questions
Summary of 2 billion redis data migration
Vscode configuration proxy
To: k210 realizes face recognition (code interpretation attached)
Dynamic routing job
Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries
一个完整的性能测试流程
Rhcsa day 1
从底层结构开始学习FPGA----RAM IP核及关键参数介绍
583. deleting two strings - Dynamic Planning
Who doesn't want a blog site of their own - build a blog site WordPress
ini解析学习文档
Golang's handwritten Web Framework
Common address collection
RSA and AES
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
MySQL数据库用户管理