【golang】队列

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

内容简介:来源:
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刷题记录


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

查看所有标签

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

数学拾遗

数学拾遗

加黑蒂 / 清华大学出版社 / 2004-8 / 49.00元

Beginning graduate students in mathematics and other quantitative subjects are expected to have a daunting breadth of mathematical knowledge ,but few have such a backgroud .This book will help stedent......一起来看看 《数学拾遗》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具