【golang】队列

栏目: Go · 发布时间: 6年前

内容简介:来源:
package datastructure 

import (
    "errors"
)

type Queue struct {
    list []int
}

func NewQueue() *Queue {
    list := make([]int, 0)
    return &Queue{list}
}

func (q *Queue) Enqueue(val int) {
    q.list = append(q.list, val)
}

func (q *Queue) Dequeue() int {
    if q.Len() == 0 {
        panic(errors.New("queue is empty"))
    }
    val := q.list[0]
    q.list = q.list[1:]
    return val
}

func (q *Queue) Len() int {
    return len(q.list)
}

来源: leetcode刷题记录


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Scalable Internet Architectures

Scalable Internet Architectures

Theo Schlossnagle / Sams Publishing / 2006-7-31 / USD 49.99

As a developer, you are aware of the increasing concern amongst developers and site architects that websites be able to handle the vast number of visitors that flood the Internet on a daily basis. Sc......一起来看看 《Scalable Internet Architectures》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器