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. 采用Opserver来监控你的ASP.NET项目系列(一、Opserver监控的简介与平台搭建)

    前言 之前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也可以看看. 今天我们主要来讲讲如何监控我们的ASP.NET项目. 首先我们来介绍一下,什么是Opserver,它是Stack ...

  2. Solr6.5.0配置中文分词器配置

    准备工作: solr6.5.0安装成功 1.去官网https://github.com/wks/ik-analyzer下载IK分词器 2.Solr集成IK a)将ik-analyzer-solr6.x ...

  3. Linux下一次删除百万文件

    Linux下一次删除百万文件 线上环境遇到的一个问题,文件数量过多,执行rm命令报错 # rm -f ./* -bash: /bin/rm: Argument list too long 根据报错检查 ...

  4. Linux分区的注意事项以及远程连接排错

    分区方式一般有三种 第一种:数据不是很重要 /boot(系统的引导分区): 系统引导的信息/软件 系统的内核   200M swap( 交换分区): 为了避免系统内存用光了导致系统 宕机 如果系统内存 ...

  5. 利用vmware搭建分布式集群

    背景:      我们需要至少3台服务器来实现分布式,鉴于没那么多钱买真机器,从学习和开发的角度看,只有虚拟机一条路了. 软件选择:     虚拟机使用VMware软件,因为主流而且资料比较多,学习成 ...

  6. 运行期以索引获取tuple元素-C++17

    //运行期以索引获取tuple元素-C++17 //需支持C++17及以上标准的编译器,VS2017 15.5.x.CodeBlocks 16.01 gcc 7.2 //参见:http://purec ...

  7. Windows Azure系列-- 配置Azure Power Shell

    1.下载Azure Power shell https://azure.microsoft.com/en-us/documentation/articles/powershell-install-co ...

  8. 7、创建ROS msg和srv

    一.msg和srv介绍 msg: msg文件使用简单的文本格式声明一个ROS message的各个域. 仅须要创建一个msg文件,就能够使用它来生成不同语言的message定义代码. srv:srv文 ...

  9. 技术债务管理以及Firefox/Chromium的债务评价

    如今的软件开发是在遍地敏捷,人人讲唯快不破的时代,哪有人有时间思考代码质量,设计的质量? 哪个又不是从一堆代码中杀出血路来实现还有一个功能?一个产品都存活不了几年,何必考虑什么可维护性? 我们追求进度 ...

  10. C#调用RESTful API

    如今非常多的网络服务都用RESTful API来实现. 比方百度的搜索推广API介绍使用Rest原因:REST+JSON风格的API相比SOAP+XML,优点是:调用更加灵活.也更easy扩展:JSO ...