#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();
}

最新文章

  1. java head space/ java.lang.OutOfMemoryError: Java heap space内存溢出
  2. C#开发分享:如何改变系统鼠标样式
  3. HDU 3743 Frosh Week(归并排序求逆序对)
  4. URLEncoder编码
  5. Ubuntu中root用户和user用户的相互切换
  6. bootstrap风格的multiselect插件——类似邮箱收件人样式
  7. window对象的属性方法名造成的命名冲突
  8. java BigInteger类的用法
  9. NGUI学习笔记(一):官方视频学习记录
  10. MVC 过滤
  11. UVA 620 Cellular Structure (dp)
  12. 201521123085 《Java程序设计》第7周学习总结
  13. Exynos4412交叉编译环境搭建
  14. nyoj 星期几?
  15. ajax跨域请求问题及解决办法总结
  16. 题解-PKUWC2018 随机算法
  17. vscode之快速生成vue模板
  18. C++ allocator
  19. struts2 拦截器弊端
  20. js数组之从数组中删除元素

热门文章

  1. process exporter 配置项解释
  2. C和指针--命令行参数
  3. sql注入原理,利用与防护
  4. Java字节码方法表与属性表深度剖析
  5. IIS设置网站为HTTPS并且将HTTP重定向到HTTPS
  6. php文件更新后不生效?亲测有效!
  7. 将vim打造成python开发工具
  8. 014_linux驱动之_信号符号名、描述和它们的信号值
  9. Shell 脚本语法
  10. moment.js 日期转换工具