You have to perform NN operations on the queue. The operations are of following type:

E xE x : Enqueue xx in the queue and print the new size of the queue.
DD : Dequeue from the queue and print the element that is deleted and the new size of the queue separated by space. If there is no element in the queue then print −1−1 in place of deleted element.

Constraints:
1≤N≤1001≤N≤100
1≤x≤1001≤x≤100

Format of the input file:
First line : N.
Next N lines : One of the above operations

Format of the output file:
For each enqueue operation print the new size of the queue. And for each dequeue operation print two integers, deleted element (−1, if queue is empty) and the new size of the queue.

该功能就是先进先出,和栈唯一不相同的就是 queue = queue[1:] 把前面的一个元素去掉

package main

import "fmt"
var queue []int func main() {
//fmt.Println("Hello World!")
queue = make([]int,0,0)
var inputCount int
fmt.Scanln(&inputCount) var flag string
var value int
var queueLength int
for i:=0;i<inputCount;i++{
fmt.Scanln(&flag,&value)
queueLength = len(queue)
if flag == "E" {
queue = append(queue,value)
queueLength = len(queue)
fmt.Println(queueLength)
}else if flag == "D"{
if queueLength ==0 {
fmt.Println("-1 0")
}else{
exitvalue:=queue[0]
queue = queue[1:]
queueLength = len(queue)
fmt.Println(exitvalue,queueLength)
}
}
}
}

  

golang 队列的更多相关文章

  1. 数据结构和算法(Golang实现)(14)常见数据结构-栈和队列

    栈和队列 一.栈 Stack 和队列 Queue 我们日常生活中,都需要将物品排列,或者安排事情的先后顺序.更通俗地讲,我们买东西时,人太多的情况下,我们要排队,排队也有先后顺序,有些人早了点来,排完 ...

  2. golang实现并发爬虫三(用队列调度器实现)

    欲看此文,必先可先看: golang实现并发爬虫一(单任务版本爬虫功能) gollang实现并发爬虫二(简单调度器) 上文中的用简单的调度器实现了并发爬虫. 并且,也提到了这种并发爬虫的实现可以提高爬 ...

  3. 用栈来实现队列的golang实现

    使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队列是否为空. ...

  4. golang 中操作nsq队列数据库

    首先先在本地将服务跑起来,我用的是docker-compose ,一句话6666 先新建一个docker-compose.yml version: '2' services: nsqlookupd: ...

  5. golang实现rabbitmq消息队列失败尝试

    在工作中发现,有些时候消息因为某些原因在消费一次后,如果消息失败,这时候不ack,消息就回一直重回队列首部,造成消息拥堵. 如是有了如下思路: 消息进入队列前,header默认有参数 retry_nu ...

  6. golang数据结构之队列

    队列可以用数组或链表实现,遵从先入先出. 目录结构: 在main中调用queue包中的属性和方法,如何调用参考另一篇文章: https://www.cnblogs.com/xiximayou/p/12 ...

  7. golang数据结构之环形队列

    目录结构: circlequeue.go package queue import ( "errors" "fmt" ) //CircleQueue 环型队列 ...

  8. golang数据结构和算法之QueueLinkedList链表队列

    队列和堆栈不一样的地方在于进出顺序: 堆栈是后进先出, 队列是先进先出. QueueLinkedList.go package QueueLinkedList type Node struct { d ...

  9. golang数据结构和算法之CircularBuffer环形缓冲队列

    慢慢练语法和思路, 想说的都在代码及注释里. CircularBuffer package CircularBuffer const arraySize = 10 type CircularBuffe ...

随机推荐

  1. .NET Core快速入门教程 2、我的第一个.NET Core App(Windows篇)

    一.前言 本篇开发环境?1.操作系统: Windows 10 X642.SDK: .NET Core 2.0 Preview 二.安装 .NET Core SDK 1.下载 .NET Core下载地址 ...

  2. 【NOIP2015提高组】信息传递

    https://www.luogu.org/problem/show?pid=2661 傻逼图论题,把我写成傻逼了. DFS找环,每个结点第二次访问时更新答案. 但是图会有几个连通块,所以要分开讨论. ...

  3. DOM操作整理

    DOM获取 1. 直接获取 document.getElementById("box_id") 通过ID获取 document.getElementsByName("my ...

  4. 使用 dotnet core 和 Azure PaaS服务进行devOps开发(Web API 实例)

    作者:陈希章 发表于 2017年12月19日 引子 这一篇文章将用一个完整的实例,给大家介绍如何基于dotnet core(微软.NET的最新版本,支持跨平台,跨设备的应用开发,详情请参考 https ...

  5. java学习笔记IO之File类

    File类总结 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times } p.p2 { margin: 0.0px 0.0px 0.0p ...

  6. 赵雅智:service与訪问者之间进行通信,数据交换

    服务类 中间人:service服务中的bind对象 创建中间人并通过onBinder方法的return暴露出去 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  7. hdu 5635 LCP Array(BC第一题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5635 LCP Array Time Limit: 4000/2000 MS (Java/Others) ...

  8. PHP中被忽略的性能优化利器:生成器

    如果是做Python或者其他语言的小伙伴,对于生成器应该不陌生.但很多PHP开发者或许都不知道生成器这个功能,可能是因为生成器是PHP 5.5.0才引入的功能,也可以是生成器作用不是很明显.但是,生成 ...

  9. 【SqlServer】【问题收集】删除同一张表中完全相同的记录

    1   概述 在Sqlserver中,当通过SqlServer设计器删除同一张表中两条完全相同的记录时,会弹出如下提示: 点击“是” 弹出如下提示,不让删除 2   问题解决 这个问题很简单,用DEL ...

  10. Apache反向代理的配置

    Apache反向代理的配置 一: Mac系统自带apache服务器 1. 查看apache版本命令如下:   sudo apachectl -v 2. 启动apache   sudo apachect ...