golang 队列
2017-09-30 13:23:37 】 浏览:9268
Tags:golang 队列

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.


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
	var flag string
	var value int
	var queueLength int
	for i:=0;i<inputCount;i++{
	    queueLength = len(queue)
	    if flag == "E" {
	        queue = append(queue,value)
	        queueLength = len(queue)
	    }else if flag == "D"{
	       if queueLength ==0 {
	           fmt.Println("-1 0")
	           queue = queue[1:]
	           queueLength = len(queue)


golang 队列

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇golang 最和谐的子序列 下一篇golang map