#pragma once
#include <iostream>
#include <iomanip>

using namespace std;

class Queue
{
  struct Node
  {
    int a;
    Node *next;
  };

  public:
    Queue();
    void push(int b);
    void pop();
    int getlength();
    virtual void print();

  private:
    Node *head;
    Node *rear;
};

void Queue::push(int 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;
}

void Queue::pop()
{
  Node *p;
  p = head->next;
  cout << " "<<setw(2)<<p->a<<setw(2)<<"出队"<< endl;
  head->next = p->next;
  delete p;
  head->a--;
}

int Queue::getlength()
{
  return head->a;
}

void Queue::print()
{
  Node *p;
  p = head->next;
  cout << "队列中的元素"<< endl;
  while (p)
  {
    cout << p->a<< "->";
    p = p->next;
  }
  cout << "NULL"<< endl;
}

Queue::Queue()
{
  rear = head = new Node();
}

Queue class的更多相关文章

  1. [数据结构]——链表(list)、队列(queue)和栈(stack)

    在前面几篇博文中曾经提到链表(list).队列(queue)和(stack),为了更加系统化,这里统一介绍着三种数据结构及相应实现. 1)链表 首先回想一下基本的数据类型,当需要存储多个相同类型的数据 ...

  2. Azure Queue Storage 基本用法 -- Azure Storage 之 Queue

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure File Storage 基 ...

  3. C++ std::queue

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

  4. 初识Message Queue之--基础篇

    之前我在项目中要用到消息队列相关的技术时,一直让Redis兼职消息队列功能,一个偶然的机会接触到了MSMQ消息队列.秉着技术还是专业的好为原则,对MSMQ进行了学习,以下是我个人的学习笔记. 一.什么 ...

  5. 搭建高可用的rabbitmq集群 + Mirror Queue + 使用C#驱动连接

    我们知道rabbitmq是一个专业的MQ产品,而且它也是一个严格遵守AMQP协议的玩意,但是要想骚,一定需要拿出高可用的东西出来,这不本篇就跟大家说 一下cluster的概念,rabbitmq是erl ...

  6. PriorityQueue和Queue的一种变体的实现

    队列和优先队列是我们十分熟悉的数据结构.提供了所谓的“先进先出”功能,优先队列则按照某种规则“先进先出”.但是他们都没有提供:“固定大小的队列”和“固定大小的优先队列”的功能. 比如我们要实现:记录按 ...

  7. C#基础---Queue(队列)的应用

       Queue队列,特性先进先出. 在一些项目中我们会遇到对一些数据的Check,如果数据不符合条件将会把不通过的信息返回到界面.但是对于有的数据可能会Check很多条件,如果一个数据一旦很多条件不 ...

  8. [LeetCode] Queue Reconstruction by Height 根据高度重建队列

    Suppose you have a random list of people standing in a queue. Each person is described by a pair of ...

  9. [LeetCode] Implement Queue using Stacks 用栈来实现队列

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  10. 源码之Queue

    看源码可以把python看得更透,更懂,想必也是开发人员的必经之路. 现在有个任务,写个线程池.使用Queue就能写一个最简单的,下面就来学学Queue源码. 源码之Queue: class Queu ...

随机推荐

  1. (1)openstack-Rabbitmq 集群部署

    一.前期准备   (1)条件:准备3台linux系统,确保配置好源,及epel源  yun1,yun2,yun3   (2)三台机器能够静态解析彼此   (3)设置可以无密钥登陆  ssh-keyge ...

  2. sql/pl 安装并连接Oracle数据库

    1,首先,先下载pl/sql devloper 安装包.下载对应版本的安装包 下载地址  https://www.allroundautomations.com/bodyplsqldevreg.htm ...

  3. less注释

    less中的注释 1.可以使用css中的注释(/***/) 2.也可以用//注释 //编译时会自动过滤掉   /**我是会被编译的*/ ul{ // padding: 0px; // height: ...

  4. Ubuntu系统---编译opencv程序的几种方式g++、Makefile、Cmake

    Ubuntu系统---编译opencv程序的几种方式g++.Makefile.Cmake 先建立一个工程(一个文件夹),写好xxx.cpp文件,可以是多个: //----------opencv.cp ...

  5. zencart批量更新后台邮箱地址sql

    zencart批量更新后台邮箱地址sql UPDATE `configuration` SET `configuration_value` = '新邮箱地址' WHERE `configuration ...

  6. 接口自动化平台搭建(四),自动化项目Jenkins持续集成

    一.Jenkins的优点 1.传统网站部署流程   一般网站部署的流程 这边是完整流程而不是简化的流程 需求分析—原型设计—开发代码—内网部署-提交测试—确认上线—备份数据—外网更新-最终测试 ,如果 ...

  7. 陈硕muduo

    https://github.com/chenshuo/muduo muduo 阅读 https://www.cnblogs.com/qbits/p/11101678.html

  8. Selenium(二)开发环境的搭建

    1.安装python的开发集成环境 我之前有写,可参考https://www.cnblogs.com/dydxw/p/10405797.html 2.使用selenium打开火狐浏览器 先从selen ...

  9. 如何实现UI自动化?DevExpress Winforms帮你忙

    DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...

  10. 前端知识体系:JavaScript基础-原型和原型链-理解 es6 中class构造以及继承的底层实现原理

    理解 es6 中class构造以及继承的底层实现原理 原文链接:https://blog.csdn.net/qq_34149805/article/details/86105123 1.ES6 cla ...