#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的更多相关文章

  1. c++ freelockquque

    http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html Class template queue boost:: ...

  2. SpringBoot2.1.0 application.properties配置

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  3. 【spring boot】application.properties官方完整文档

    官方地址: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 进入搜索: Appendice ...

  4. C++ std::queue

    std::queue template <class T, class Container = deque<T> > class queue; FIFO queue queue ...

  5. [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)

    再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...

  6. [C++][数据结构]队列(queue)的实现

    对于队列的定义,前人之述备矣. 队列的实现方法与栈非常相似.我直接在我实现的那个栈的代码上加了一点东西,全局替换了一些标识符,就实现了这个队列. 我实现的是一个queue<value>容器 ...

  7. STL容器适配器 stack, queue

    stack是一种后进先出(last in first out)的数据结构.它只有一个出口,如图所示.stack允许新增元素,删除元素,取得最顶端元素.但除了最顶端外,没有其他任何地方可以存储stack ...

  8. member template

    1.当且仅当类模板的参数相同时,你才能对类实体对象相互赋值,即将一个实体对象整体赋值给另外一个实体对象.不能将一种类型的实体对象赋值给另外一种实体对象.如: Stack<int> intS ...

  9. [c++] STL = Standard Template Library

    How many people give up, because of YOU. Continue... 先实践,最后需要总结. 1. 数据流中的数据按照一定的格式<T>提取 ------ ...

随机推荐

  1. ImportError: No module named yaml

    问题: import yaml ImportError: No module named yaml 解决: wget http://pyyaml.org/download/pyyaml/PyYAML- ...

  2. Mount 使用方法

    NAME mount - 挂载文件系统 SYNOPSIS 总览 mount [-lhV] mount -a [-fFnrsvw] [-t vfstype] [-O optlist] mount [-f ...

  3. 04 Windows编程——Unicode

    VS 2017下源码 #include<stdio.h> int main() { char ASC_a = 'a'; char *ASC_str = "hello"; ...

  4. dbm和发射功率得对照表

    原文链接:https://blog.csdn.net/nicholas_dlut/article/details/80950163dBm mW 下面是dbm和发射功率得对照表. 基本上市面上所有的无线 ...

  5. <转载>c++中new一个二维数组

    原文连接 在c++中定义一个二维数组时有多种方式,下面是几种定义方式的说明:其中dataType 表示数据类型,如int  byte  long... 1.dataType (*num)[n] = n ...

  6. Linux 02 Linux基本概念及操作

    基本echo "hello word"  输出 hello wordtouch file         创建文件名为file 常用快捷键TAB:在忘记命令时,可以用来补全命令Ct ...

  7. 记录一些python内置函数

    整理一些内置函数,平时用得比较少,但是时不时遇上,记录一下吧(嘻嘻(●'◡'●)) 1.help() 查看模块or函数的帮助文档 help(pandas) #模块 Help on package pa ...

  8. spark几个错误

    一.java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream.<init>(Ljava/io/InputStream ...

  9. 保护你的Linux系统的九个老生常谈

    在现在这个世道中,保障基于Linux的系统的安全是十分重要的.但是,你得知道怎么干.一个简单反恶意程序软件是远远不够的,你需要采取其它措施来协同工作.那么试试下面这些手段吧. 1. 使用SELinux ...

  10. The "web.xml" is called web application deployment descriptor

    3.3  Configure the Application Deployment Descriptor - "web.xml" A web user invokes a serv ...