c++ template Queue
#pragma once
#include <iostream>
#include <iomanip>
using namespace std;
template<class T>
class Queue
{
struct Node
{
T a;
Node *next;
};
public:
Queue();
void push(T b);
void pop();
int getlength();
virtual void print();
private:
Node *head;
Node *rear;
};
template<class T>
void Queue<T>::push(T b)
{
Node *p1 = new Node;
p1->a = b;
p1->next = NULL;
rear->next = p1;
rear = p1;
head->a++;
cout << setw(2) << b << setw(2) << "进入队列" << endl;
}
template<class T>
void Queue<T>::pop()
{
Node *p;
p = head->next;
cout << " " << setw(2) << p->a << setw(2) << "出队" << endl;
head->next = p->next;
delete p;
head->a--;
}
template<class T>
int Queue<T>::getlength()
{
return head->a;
}
template<class T>
void Queue<T>::print()
{
Node *p;
p = head->next;
cout << "队列中的元素" << endl;
while (p)
{
cout << p->a << "->";
p = p->next;
}
cout << "NULL" << endl;
}
template<class T>
Queue<T>::Queue()
{
rear = head = new Node();
}
c++ template Queue的更多相关文章
- c++ freelockquque
http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html Class template queue boost:: ...
- SpringBoot2.1.0 application.properties配置
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- 【spring boot】application.properties官方完整文档
官方地址: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 进入搜索: Appendice ...
- C++ std::queue
std::queue template <class T, class Container = deque<T> > class queue; FIFO queue queue ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- [C++][数据结构]队列(queue)的实现
对于队列的定义,前人之述备矣. 队列的实现方法与栈非常相似.我直接在我实现的那个栈的代码上加了一点东西,全局替换了一些标识符,就实现了这个队列. 我实现的是一个queue<value>容器 ...
- STL容器适配器 stack, queue
stack是一种后进先出(last in first out)的数据结构.它只有一个出口,如图所示.stack允许新增元素,删除元素,取得最顶端元素.但除了最顶端外,没有其他任何地方可以存储stack ...
- member template
1.当且仅当类模板的参数相同时,你才能对类实体对象相互赋值,即将一个实体对象整体赋值给另外一个实体对象.不能将一种类型的实体对象赋值给另外一种实体对象.如: Stack<int> intS ...
- [c++] STL = Standard Template Library
How many people give up, because of YOU. Continue... 先实践,最后需要总结. 1. 数据流中的数据按照一定的格式<T>提取 ------ ...
随机推荐
- NORDIC ble RSSI
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context) { ret_code_t err_code; sw ...
- Splay树详解
更好的阅读体验 Splay树 这是一篇宏伟的巨篇 首先介绍BST,也就是所有平衡树的开始,他的China名字是二叉查找树. BST性质简介 给定一棵二叉树,每一个节点有一个权值,命名为 ** 关键码 ...
- python 2.7安装pygame报错解决办法pygame-1.9.4-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.
python下载python安装包 https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame 下载完后进入cmd命令行执行安装,报错: pygame-1.9 ...
- jquery动态背景切换全屏登录插件supersized.js
下载地址:https://download.csdn.net/download/t101lian/10434198预览: http://www.daimabiji.com/codedemo/1530 ...
- React 新特性学习
1 context 2 contextType 3 lazy 4 suspense 5 memo 6 hooks 7 effect hooks =========== 1 Context 提供了一种方 ...
- WebLogic 12c 版 下载与安装(ubuntu)
下载地址:https://www.oracle.com/middleware/technologies/fusionmiddleware-downloads.html 参考地址:https://blo ...
- 通过德鲁伊druid给系统增加监控
系统在线上运行了一段时间后,比如一年半载的,我们发现系统可能存在某些问题,比如执行系统变慢了,比如某些spring的bean无法监控各种调用情况. 触发到db的各种执行情况,这个时候,我们就需要一个工 ...
- redis在linux服务器部署
0)参考资料 http://www.cnblogs.com/liuling/p/2014-4-19-02.html 1)下载安装包地址 http://download.redis.io/release ...
- myEclipse设置
字符集设置 点击菜单:window——preferences 输入:Workspace 字体大小设置 输入:colors and fonts 本机字体:14 显示行号 输入:Text Editors ...
- 【51nod 1340】地铁环线
题目 有一个地铁环线,环线中有N个站台,标号为0,1,2,...,N-1.这个环线是单行线,一共由N条有向边构成,即从0到1,1到2,..k到k+1,...,N-2到N-1,N-1到0各有一条边.定义 ...